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 #ifndef CC_BASE_HISTOGRAMS_H_
6 #define CC_BASE_HISTOGRAMS_H_
8 #include "base/compiler_specific.h"
9 #include "base/metrics/histogram_base.h"
10 #include "base/metrics/histogram_macros.h"
11 #include "base/numerics/safe_math.h"
12 #include "base/time/time.h"
13 #include "base/timer/elapsed_timer.h"
14 #include "cc/base/cc_export.h"
18 // Emits UMA histogram trackers for time spent as well as area (in pixels)
19 // processed per unit time. Time is measured in microseconds, and work in
20 // pixels per millisecond.
23 // // Outside of a method, perhaps in a namespace.
24 // DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(ScopedReticulateSplinesTimer,
25 // "ReticulateSplinesUs",
26 // "ReticulateSplinesPixelsPerMs");
28 // // Inside a method.
29 // ScopedReticulateSplinesTimer timer;
30 // timer.AddArea(some_rect.size().GetArea());
31 #define DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(class_name, time_histogram, \
33 class class_name : public ::cc::ScopedUMAHistogramAreaTimerBase { \
37 class_name::~class_name() { \
40 if (GetHistogramValues(&time_sample, &area_sample)) { \
41 UMA_HISTOGRAM_COUNTS(time_histogram, time_sample); \
42 UMA_HISTOGRAM_COUNTS(area_histogram, area_sample); \
46 class CC_EXPORT ScopedUMAHistogramAreaTimerBase
{
48 void AddArea(int area
) { area_
+= area
; }
49 void SetArea(int area
) { area_
= area
; }
52 using Sample
= base::HistogramBase::Sample
;
54 ScopedUMAHistogramAreaTimerBase();
55 ~ScopedUMAHistogramAreaTimerBase();
57 // Returns true if histograms should be recorded (i.e. values are valid).
58 bool GetHistogramValues(Sample
* time_microseconds
,
59 Sample
* pixels_per_ms
) const;
62 static bool GetHistogramValues(base::TimeDelta elapsed
,
64 Sample
* time_microseconds
,
65 Sample
* pixels_per_ms
);
67 base::ElapsedTimer timer_
;
68 base::CheckedNumeric
<int> area_
;
70 friend class ScopedUMAHistogramAreaTimerBaseTest
;
71 DISALLOW_COPY_AND_ASSIGN(ScopedUMAHistogramAreaTimerBase
);
76 #endif // CC_BASE_HISTOGRAMS_H_