Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / cc / base / histograms.h
blob6f42428efb9943b1362afe871a719fa5c4bc1cc8
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 GetHistogramValues(&time_sample, &area_sample); \
41 UMA_HISTOGRAM_COUNTS(time_histogram, time_sample); \
42 UMA_HISTOGRAM_COUNTS(area_histogram, area_sample); \
45 class CC_EXPORT ScopedUMAHistogramAreaTimerBase {
46 public:
47 void AddArea(int area) { area_ += area; }
48 void SetArea(int area) { area_ = area; }
50 protected:
51 using Sample = base::HistogramBase::Sample;
53 ScopedUMAHistogramAreaTimerBase();
54 ~ScopedUMAHistogramAreaTimerBase();
56 // Returns true if histograms should be recorded (i.e. values are valid).
57 void GetHistogramValues(Sample* time_microseconds,
58 Sample* pixels_per_ms) const;
60 private:
61 static void GetHistogramValues(base::TimeDelta elapsed,
62 int area,
63 Sample* time_microseconds,
64 Sample* pixels_per_ms);
66 base::ElapsedTimer timer_;
67 base::CheckedNumeric<int> area_;
69 friend class ScopedUMAHistogramAreaTimerBaseTest;
70 DISALLOW_COPY_AND_ASSIGN(ScopedUMAHistogramAreaTimerBase);
73 } // namespace cc
75 #endif // CC_BASE_HISTOGRAMS_H_