Automated Commit: Committing new LKGM version 7252.0.0 for chromeos.
[chromium-blink-merge.git] / cc / base / histograms.h
blob0c8a2bc8532e627a3d9c03fedafdd0248fb8c502
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"
16 namespace cc {
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.
22 // Usage:
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, \
32 area_histogram) \
33 class class_name : public ::cc::ScopedUMAHistogramAreaTimerBase { \
34 public: \
35 ~class_name(); \
36 }; \
37 class_name::~class_name() { \
38 Sample time_sample; \
39 Sample area_sample; \
40 if (GetHistogramValues(&time_sample, &area_sample)) { \
41 UMA_HISTOGRAM_COUNTS(time_histogram, time_sample); \
42 UMA_HISTOGRAM_COUNTS(area_histogram, area_sample); \
43 } \
46 class CC_EXPORT ScopedUMAHistogramAreaTimerBase {
47 public:
48 void AddArea(int area) { area_ += area; }
49 void SetArea(int area) { area_ = area; }
51 protected:
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;
61 private:
62 static bool GetHistogramValues(base::TimeDelta elapsed,
63 int area,
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);
74 } // namespace cc
76 #endif // CC_BASE_HISTOGRAMS_H_