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::TimeTicks::Now().ToInternalValue() /
25 static_cast<double>(base::Time::kMicrosecondsPerSecond
);
28 const unsigned char* ANGLEPlatformImpl::getTraceCategoryEnabledFlag(
29 const char* category_group
) {
30 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group
);
33 angle::Platform::TraceEventHandle
ANGLEPlatformImpl::addTraceEvent(
35 const unsigned char* category_group_enabled
,
37 unsigned long long id
,
40 const char** arg_names
,
41 const unsigned char* arg_types
,
42 const unsigned long long* arg_values
,
43 unsigned char flags
) {
44 base::TimeTicks timestamp_tt
= base::TimeTicks::FromInternalValue(
45 static_cast<int64
>(timestamp
* base::Time::kMicrosecondsPerSecond
));
46 base::trace_event::TraceEventHandle handle
=
47 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
48 phase
, category_group_enabled
, name
, id
,
49 base::PlatformThread::CurrentId(), timestamp_tt
, num_args
, arg_names
,
50 arg_types
, arg_values
, nullptr, flags
);
51 angle::Platform::TraceEventHandle result
;
52 memcpy(&result
, &handle
, sizeof(result
));
56 void ANGLEPlatformImpl::updateTraceEventDuration(
57 const unsigned char* category_group_enabled
,
59 TraceEventHandle handle
) {
60 base::trace_event::TraceEventHandle trace_event_handle
;
61 memcpy(&trace_event_handle
, &handle
, sizeof(handle
));
62 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled
, name
,
66 void ANGLEPlatformImpl::histogramCustomCounts(const char* name
,
71 // Copied from histogram macro, but without the static variable caching
72 // the histogram because name is dynamic.
73 base::HistogramBase
* counter
= base::Histogram::FactoryGet(
74 name
, min
, max
, bucket_count
,
75 base::HistogramBase::kUmaTargetedHistogramFlag
);
76 DCHECK_EQ(name
, counter
->histogram_name());
80 void ANGLEPlatformImpl::histogramEnumeration(const char* name
,
83 // Copied from histogram macro, but without the static variable caching
84 // the histogram because name is dynamic.
85 base::HistogramBase
* counter
= base::LinearHistogram::FactoryGet(
86 name
, 1, boundary_value
, boundary_value
+ 1,
87 base::HistogramBase::kUmaTargetedHistogramFlag
);
88 DCHECK_EQ(name
, counter
->histogram_name());
92 void ANGLEPlatformImpl::histogramSparse(const char* name
, int sample
) {
93 // For sparse histograms, we can use the macro, as it does not incorporate a
95 UMA_HISTOGRAM_SPARSE_SLOWLY(name
, sample
);