Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: cc/base/histograms.h

Issue 1139743004: cc: Reland "Add UMA stats for record and raster time." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge with master (conflicts with cc/resources move) Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef CC_BASE_HISTOGRAMS_H_
6 #define CC_BASE_HISTOGRAMS_H_
7
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"
15
16 namespace cc {
17
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.
21 //
22 // Usage:
23 // // Outside of a method, perhaps in a namespace.
24 // DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(ScopedReticulateSplinesTimer,
25 // "ReticulateSplinesUs",
26 // "ReticulateSplinesPixelsPerMs");
27 //
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 } \
44 }
45
46 class CC_EXPORT ScopedUMAHistogramAreaTimerBase {
47 public:
48 void AddArea(int area) { area_ += area; }
49 void SetArea(int area) { area_ = area; }
50
51 protected:
52 using Sample = base::HistogramBase::Sample;
53
54 ScopedUMAHistogramAreaTimerBase();
55 ~ScopedUMAHistogramAreaTimerBase();
56
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;
60
61 private:
62 static bool GetHistogramValues(base::TimeDelta elapsed,
63 int area,
64 Sample* time_microseconds,
65 Sample* pixels_per_ms);
66
67 base::ElapsedTimer timer_;
68 base::CheckedNumeric<int> area_;
69
70 friend class ScopedUMAHistogramAreaTimerBaseTest;
71 DISALLOW_COPY_AND_ASSIGN(ScopedUMAHistogramAreaTimerBase);
72 };
73
74 } // namespace cc
75
76 #endif // CC_BASE_HISTOGRAMS_H_
OLDNEW
« no previous file with comments | « cc/base/BUILD.gn ('k') | cc/base/histograms.cc » ('j') | cc/base/histograms.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698