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::monotonicallyIncreasingTime() {
20 return base::TimeTicks::Now().ToInternalValue() /
21 static_cast<double>(base::Time::kMicrosecondsPerSecond
);
24 const unsigned char* ANGLEPlatformImpl::getTraceCategoryEnabledFlag(
25 const char* category_group
) {
26 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group
);
29 angle::Platform::TraceEventHandle
ANGLEPlatformImpl::addTraceEvent(
31 const unsigned char* category_group_enabled
,
33 unsigned long long id
,
36 const char** arg_names
,
37 const unsigned char* arg_types
,
38 const unsigned long long* arg_values
,
39 unsigned char flags
) {
40 base::TimeTicks timestamp_tt
= base::TimeTicks::FromInternalValue(
41 static_cast<int64
>(timestamp
* base::Time::kMicrosecondsPerSecond
));
42 base::trace_event::TraceEventHandle handle
=
43 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
44 phase
, category_group_enabled
, name
, id
,
45 base::PlatformThread::CurrentId(), timestamp_tt
, num_args
, arg_names
,
46 arg_types
, arg_values
, nullptr, flags
);
47 angle::Platform::TraceEventHandle result
;
48 memcpy(&result
, &handle
, sizeof(result
));
52 void ANGLEPlatformImpl::updateTraceEventDuration(
53 const unsigned char* category_group_enabled
,
55 TraceEventHandle handle
) {
56 base::trace_event::TraceEventHandle trace_event_handle
;
57 memcpy(&trace_event_handle
, &handle
, sizeof(handle
));
58 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled
, name
,
62 void ANGLEPlatformImpl::histogramCustomCounts(const char* name
,
67 // Copied from histogram macro, but without the static variable caching
68 // the histogram because name is dynamic.
69 base::HistogramBase
* counter
= base::Histogram::FactoryGet(
70 name
, min
, max
, bucket_count
,
71 base::HistogramBase::kUmaTargetedHistogramFlag
);
72 DCHECK_EQ(name
, counter
->histogram_name());
76 void ANGLEPlatformImpl::histogramEnumeration(const char* name
,
79 // Copied from histogram macro, but without the static variable caching
80 // the histogram because name is dynamic.
81 base::HistogramBase
* counter
= base::LinearHistogram::FactoryGet(
82 name
, 1, boundary_value
, boundary_value
+ 1,
83 base::HistogramBase::kUmaTargetedHistogramFlag
);
84 DCHECK_EQ(name
, counter
->histogram_name());
88 void ANGLEPlatformImpl::histogramSparse(const char* name
, int sample
) {
89 // For sparse histograms, we can use the macro, as it does not incorporate a
91 UMA_HISTOGRAM_SPARSE_SLOWLY(name
, sample
);