| 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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // ScopedReticulateSplinesTimer, | 43 // ScopedReticulateSplinesTimer, |
| 44 // "Compositing.%s.ReticulateSplinesUs", | 44 // "Compositing.%s.ReticulateSplinesUs", |
| 45 // "Compositing.%s.ReticulateSplinesPixelsPerMs"); | 45 // "Compositing.%s.ReticulateSplinesPixelsPerMs"); |
| 46 // | 46 // |
| 47 // // Inside a method. | 47 // // Inside a method. |
| 48 // ScopedReticulateSplinesTimer timer; | 48 // ScopedReticulateSplinesTimer timer; |
| 49 // timer.AddArea(some_rect.size().GetArea()); | 49 // timer.AddArea(some_rect.size().GetArea()); |
| 50 // | 50 // |
| 51 #define DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(class_name, time_histogram, \ | 51 #define DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(class_name, time_histogram, \ |
| 52 area_histogram) \ | 52 area_histogram) \ |
| 53 class class_name : public ::cc::ScopedUMAHistogramAreaTimerBase { \ | 53 class class_name : public ScopedUMAHistogramAreaTimerBase { \ |
| 54 public: \ | 54 public: \ |
| 55 ~class_name(); \ | 55 ~class_name(); \ |
| 56 }; \ | 56 }; \ |
| 57 class_name::~class_name() { \ | 57 class_name::~class_name() { \ |
| 58 Sample time_sample; \ | 58 Sample time_sample; \ |
| 59 Sample area_sample; \ | 59 Sample area_sample; \ |
| 60 const char* client_name = ::cc::GetClientNameForMetrics(); \ | 60 const char* client_name = GetClientNameForMetrics(); \ |
| 61 if (client_name && GetHistogramValues(&time_sample, &area_sample)) { \ | 61 if (client_name && GetHistogramValues(&time_sample, &area_sample)) { \ |
| 62 /* GetClientNameForMetrics only returns one non-null value over */ \ | 62 /* GetClientNameForMetrics only returns one non-null value over */ \ |
| 63 /* the lifetime of the process, so these histogram names are */ \ | 63 /* the lifetime of the process, so these histogram names are */ \ |
| 64 /* runtime constant. */ \ | 64 /* runtime constant. */ \ |
| 65 UMA_HISTOGRAM_COUNTS(base::StringPrintf(time_histogram, client_name), \ | 65 UMA_HISTOGRAM_COUNTS(base::StringPrintf(time_histogram, client_name), \ |
| 66 time_sample); \ | 66 time_sample); \ |
| 67 UMA_HISTOGRAM_COUNTS(base::StringPrintf(area_histogram, client_name), \ | 67 UMA_HISTOGRAM_COUNTS(base::StringPrintf(area_histogram, client_name), \ |
| 68 area_sample); \ | 68 area_sample); \ |
| 69 } \ | 69 } \ |
| 70 } | 70 } |
| 71 | 71 |
| 72 // Version of the above macro for cases which only care about time, not area. |
| 73 #define DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(class_name, time_histogram) \ |
| 74 class class_name : public ScopedUMAHistogramAreaTimerBase { \ |
| 75 public: \ |
| 76 ~class_name(); \ |
| 77 }; \ |
| 78 class_name::~class_name() { \ |
| 79 Sample time_sample; \ |
| 80 Sample area_sample; \ |
| 81 const char* client_name = GetClientNameForMetrics(); \ |
| 82 if (client_name && GetHistogramValues(&time_sample, &area_sample)) { \ |
| 83 DCHECK_EQ(0, area_sample); \ |
| 84 /* GetClientNameForMetrics only returns one non-null value over */ \ |
| 85 /* the lifetime of the process, so these histogram names are */ \ |
| 86 /* runtime constant. */ \ |
| 87 UMA_HISTOGRAM_COUNTS(base::StringPrintf(time_histogram, client_name), \ |
| 88 time_sample); \ |
| 89 } \ |
| 90 } |
| 91 |
| 72 class CC_EXPORT ScopedUMAHistogramAreaTimerBase { | 92 class CC_EXPORT ScopedUMAHistogramAreaTimerBase { |
| 73 public: | 93 public: |
| 74 void AddArea(const base::CheckedNumeric<int>& area) { area_ += area; } | 94 void AddArea(const base::CheckedNumeric<int>& area) { area_ += area; } |
| 75 void SetArea(const base::CheckedNumeric<int>& area) { area_ = area; } | 95 void SetArea(const base::CheckedNumeric<int>& area) { area_ = area; } |
| 76 | 96 |
| 77 protected: | 97 protected: |
| 78 using Sample = base::HistogramBase::Sample; | 98 using Sample = base::HistogramBase::Sample; |
| 79 | 99 |
| 80 ScopedUMAHistogramAreaTimerBase(); | 100 ScopedUMAHistogramAreaTimerBase(); |
| 81 ~ScopedUMAHistogramAreaTimerBase(); | 101 ~ScopedUMAHistogramAreaTimerBase(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 base::ElapsedTimer timer_; | 113 base::ElapsedTimer timer_; |
| 94 base::CheckedNumeric<int> area_; | 114 base::CheckedNumeric<int> area_; |
| 95 | 115 |
| 96 friend class ScopedUMAHistogramAreaTimerBaseTest; | 116 friend class ScopedUMAHistogramAreaTimerBaseTest; |
| 97 DISALLOW_COPY_AND_ASSIGN(ScopedUMAHistogramAreaTimerBase); | 117 DISALLOW_COPY_AND_ASSIGN(ScopedUMAHistogramAreaTimerBase); |
| 98 }; | 118 }; |
| 99 | 119 |
| 100 } // namespace cc | 120 } // namespace cc |
| 101 | 121 |
| 102 #endif // CC_BASE_HISTOGRAMS_H_ | 122 #endif // CC_BASE_HISTOGRAMS_H_ |
| OLD | NEW |