OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_BASE_HISTOGRAMS_H_ | 5 #ifndef CC_BASE_HISTOGRAMS_H_ |
6 #define CC_BASE_HISTOGRAMS_H_ | 6 #define CC_BASE_HISTOGRAMS_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/metrics/histogram_base.h" | 10 #include "base/metrics/histogram_base.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/numerics/safe_math.h" | 12 #include "base/numerics/safe_math.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "base/timer/elapsed_timer.h" | 15 #include "base/timer/elapsed_timer.h" |
16 #include "cc/base/cc_export.h" | 16 #include "cc/base/base_export.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 // Supplies a client name to be inserted into histogram names. | 20 // Supplies a client name to be inserted into histogram names. |
21 // These are known so far: Renderer, Browser | 21 // These are known so far: Renderer, Browser |
22 // | 22 // |
23 // We currently assume that there is only one distinct client per process. | 23 // We currently assume that there is only one distinct client per process. |
24 // Not thread-safe. If called multiple times, warns and skips metrics. | 24 // Not thread-safe. If called multiple times, warns and skips metrics. |
25 CC_EXPORT void SetClientNameForMetrics(const char* client_name); | 25 CC_BASE_EXPORT void SetClientNameForMetrics(const char* client_name); |
26 | 26 |
27 // Returns the client name, for use by applicable cc metrics code. | 27 // Returns the client name, for use by applicable cc metrics code. |
28 // May return null, in which case no clients, or at least two clients, set the | 28 // May return null, in which case no clients, or at least two clients, set the |
29 // client name, and these metrics should be omitted. | 29 // client name, and these metrics should be omitted. |
30 // | 30 // |
31 // This method guarantees that it will never return two distinct non-null | 31 // This method guarantees that it will never return two distinct non-null |
32 // values over the lifetime of the process. | 32 // values over the lifetime of the process. |
33 const char* GetClientNameForMetrics(); | 33 CC_BASE_EXPORT const char* GetClientNameForMetrics(); |
34 | 34 |
35 // Emits UMA histogram trackers for time spent as well as area (in pixels) | 35 // Emits UMA histogram trackers for time spent as well as area (in pixels) |
36 // processed per unit time. Time is measured in microseconds, and work in | 36 // processed per unit time. Time is measured in microseconds, and work in |
37 // pixels per millisecond. Histogram name should include a %s to grab the client | 37 // pixels per millisecond. Histogram name should include a %s to grab the client |
38 // name. | 38 // name. |
39 // | 39 // |
40 // Usage: | 40 // Usage: |
41 // // Outside of a method, perhaps in a namespace. | 41 // // Outside of a method, perhaps in a namespace. |
42 // DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( | 42 // DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( |
43 // ScopedReticulateSplinesTimer, | 43 // ScopedReticulateSplinesTimer, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (client_name && GetHistogramValues(&time_sample, &area_sample)) { \ | 83 if (client_name && GetHistogramValues(&time_sample, &area_sample)) { \ |
84 DCHECK_EQ(0, area_sample); \ | 84 DCHECK_EQ(0, area_sample); \ |
85 /* GetClientNameForMetrics only returns one non-null value over */ \ | 85 /* GetClientNameForMetrics only returns one non-null value over */ \ |
86 /* the lifetime of the process, so these histogram names are */ \ | 86 /* the lifetime of the process, so these histogram names are */ \ |
87 /* runtime constant. */ \ | 87 /* runtime constant. */ \ |
88 UMA_HISTOGRAM_COUNTS(base::StringPrintf(time_histogram, client_name), \ | 88 UMA_HISTOGRAM_COUNTS(base::StringPrintf(time_histogram, client_name), \ |
89 time_sample); \ | 89 time_sample); \ |
90 } \ | 90 } \ |
91 } | 91 } |
92 | 92 |
93 class CC_EXPORT ScopedUMAHistogramAreaTimerBase { | 93 class CC_BASE_EXPORT ScopedUMAHistogramAreaTimerBase { |
94 public: | 94 public: |
95 void AddArea(const base::CheckedNumeric<int>& area) { area_ += area; } | 95 void AddArea(const base::CheckedNumeric<int>& area) { area_ += area; } |
96 void SetArea(const base::CheckedNumeric<int>& area) { area_ = area; } | 96 void SetArea(const base::CheckedNumeric<int>& area) { area_ = area; } |
97 | 97 |
98 protected: | 98 protected: |
99 using Sample = base::HistogramBase::Sample; | 99 using Sample = base::HistogramBase::Sample; |
100 | 100 |
101 ScopedUMAHistogramAreaTimerBase(); | 101 ScopedUMAHistogramAreaTimerBase(); |
102 ~ScopedUMAHistogramAreaTimerBase(); | 102 ~ScopedUMAHistogramAreaTimerBase(); |
103 | 103 |
(...skipping 10 matching lines...) Expand all Loading... |
114 base::ElapsedTimer timer_; | 114 base::ElapsedTimer timer_; |
115 base::CheckedNumeric<int> area_; | 115 base::CheckedNumeric<int> area_; |
116 | 116 |
117 friend class ScopedUMAHistogramAreaTimerBaseTest; | 117 friend class ScopedUMAHistogramAreaTimerBaseTest; |
118 DISALLOW_COPY_AND_ASSIGN(ScopedUMAHistogramAreaTimerBase); | 118 DISALLOW_COPY_AND_ASSIGN(ScopedUMAHistogramAreaTimerBase); |
119 }; | 119 }; |
120 | 120 |
121 } // namespace cc | 121 } // namespace cc |
122 | 122 |
123 #endif // CC_BASE_HISTOGRAMS_H_ | 123 #endif // CC_BASE_HISTOGRAMS_H_ |
OLD | NEW |