1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/gl/angle_platform_impl.h"
7 #include "base/metrics/histogram.h"
8 #include "base/metrics/sparse_histogram.h"
9 #include "base/trace_event/trace_event.h"
13 ANGLEPlatformImpl::ANGLEPlatformImpl() {
16 ANGLEPlatformImpl::~ANGLEPlatformImpl() {
19 double ANGLEPlatformImpl::currentTime() {
20 return base::Time::Now().ToDoubleT();
23 double ANGLEPlatformImpl::monotonicallyIncreasingTime() {
24 return (base::TraceTicks::Now() - base::TraceTicks()).InSecondsF();
27 const unsigned char* ANGLEPlatformImpl::getTraceCategoryEnabledFlag(
28 const char* category_group
) {
29 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group
);
32 angle::Platform::TraceEventHandle
ANGLEPlatformImpl::addTraceEvent(
34 const unsigned char* category_group_enabled
,
36 unsigned long long id
,
39 const char** arg_names
,
40 const unsigned char* arg_types
,
41 const unsigned long long* arg_values
,
42 unsigned char flags
) {
43 base::TraceTicks timestamp_tt
=
44 base::TraceTicks() + base::TimeDelta::FromSecondsD(timestamp
);
45 base::trace_event::TraceEventHandle handle
=
46 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
47 phase
, category_group_enabled
, name
, id
, trace_event_internal::kNoId
,
48 base::PlatformThread::CurrentId(), timestamp_tt
, num_args
, arg_names
,
49 arg_types
, arg_values
, nullptr, flags
);
50 angle::Platform::TraceEventHandle result
;
51 memcpy(&result
, &handle
, sizeof(result
));
55 void ANGLEPlatformImpl::updateTraceEventDuration(
56 const unsigned char* category_group_enabled
,
58 TraceEventHandle handle
) {
59 base::trace_event::TraceEventHandle trace_event_handle
;
60 memcpy(&trace_event_handle
, &handle
, sizeof(handle
));
61 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled
, name
,
65 void ANGLEPlatformImpl::histogramCustomCounts(const char* name
,
70 // Copied from histogram macro, but without the static variable caching
71 // the histogram because name is dynamic.
72 base::HistogramBase
* counter
= base::Histogram::FactoryGet(
73 name
, min
, max
, bucket_count
,
74 base::HistogramBase::kUmaTargetedHistogramFlag
);
75 DCHECK_EQ(name
, counter
->histogram_name());
79 void ANGLEPlatformImpl::histogramEnumeration(const char* name
,
82 // Copied from histogram macro, but without the static variable caching
83 // the histogram because name is dynamic.
84 base::HistogramBase
* counter
= base::LinearHistogram::FactoryGet(
85 name
, 1, boundary_value
, boundary_value
+ 1,
86 base::HistogramBase::kUmaTargetedHistogramFlag
);
87 DCHECK_EQ(name
, counter
->histogram_name());
91 void ANGLEPlatformImpl::histogramSparse(const char* name
, int sample
) {
92 // For sparse histograms, we can use the macro, as it does not incorporate a
94 UMA_HISTOGRAM_SPARSE_SLOWLY(name
, sample
);
97 void ANGLEPlatformImpl::histogramBoolean(const char* name
, bool sample
) {
98 histogramEnumeration(name
, sample
? 1 : 0, 2);