| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 Histogram_h | 5 #ifndef Histogram_h |
| 6 #define Histogram_h | 6 #define Histogram_h |
| 7 | 7 |
| 8 #include "base/metrics/histogram_base.h" | 8 #include "base/metrics/histogram_base.h" |
| 9 #include "platform/PlatformExport.h" | 9 #include "platform/PlatformExport.h" |
| 10 #include "wtf/CurrentTime.h" |
| 10 #include <stdint.h> | 11 #include <stdint.h> |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 class HistogramBase; | 14 class HistogramBase; |
| 14 }; | 15 }; |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 class PLATFORM_EXPORT CustomCountHistogram { | 19 class PLATFORM_EXPORT CustomCountHistogram { |
| 19 public: | 20 public: |
| 20 CustomCountHistogram(const char* name, base::HistogramBase::Sample min, base
::HistogramBase::Sample max, int32_t bucketCount); | 21 CustomCountHistogram(const char* name, base::HistogramBase::Sample min, base
::HistogramBase::Sample max, int32_t bucketCount); |
| 21 void count(base::HistogramBase::Sample); | 22 void count(base::HistogramBase::Sample); |
| 22 | 23 |
| 23 protected: | 24 protected: |
| 24 explicit CustomCountHistogram(base::HistogramBase*); | 25 explicit CustomCountHistogram(base::HistogramBase*); |
| 25 | 26 |
| 26 private: | |
| 27 base::HistogramBase* m_histogram; | 27 base::HistogramBase* m_histogram; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 class PLATFORM_EXPORT EnumerationHistogram : public CustomCountHistogram { | 30 class PLATFORM_EXPORT EnumerationHistogram : public CustomCountHistogram { |
| 31 public: | 31 public: |
| 32 EnumerationHistogram(const char* name, base::HistogramBase::Sample boundaryV
alue); | 32 EnumerationHistogram(const char* name, base::HistogramBase::Sample boundaryV
alue); |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class PLATFORM_EXPORT SparseHistogram { | 35 class PLATFORM_EXPORT SparseHistogram { |
| 36 public: | 36 public: |
| 37 explicit SparseHistogram(const char* name); | 37 explicit SparseHistogram(const char* name); |
| 38 | 38 |
| 39 void sample(base::HistogramBase::Sample); | 39 void sample(base::HistogramBase::Sample); |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 base::HistogramBase* m_histogram; | 42 base::HistogramBase* m_histogram; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 |
| 46 |
| 47 class PLATFORM_EXPORT ScopedUsHistogramTimer { |
| 48 public: |
| 49 ScopedUsHistogramTimer(CustomCountHistogram& counter) |
| 50 : m_startTime(WTF::monotonicallyIncreasingTime()), |
| 51 m_counter(counter) {} |
| 52 |
| 53 ~ScopedUsHistogramTimer() |
| 54 { |
| 55 m_counter.count((WTF::monotonicallyIncreasingTime() - m_startTime) * ba
se::Time::kMicrosecondsPerSecond); |
| 56 } |
| 57 |
| 58 private: |
| 59 // In seconds. |
| 60 double m_startTime; |
| 61 CustomCountHistogram& m_counter; |
| 62 }; |
| 63 |
| 64 // Use code like this to record time, in microseconds, to execute a block of cod
e: |
| 65 // |
| 66 // { |
| 67 // SCOPED_BLINK_UMA_HISTOGRAM_TIMER(myUmaStatName) |
| 68 // RunMyCode(); |
| 69 // } |
| 70 // This macro records all times between 0us and 10 seconds. |
| 71 // Do not change this macro without renaming all metrics that use it! |
| 72 #define SCOPED_BLINK_UMA_HISTOGRAM_TIMER(name) \ |
| 73 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounter, (name, 0, 10000000, 5
0)); \ |
| 74 ScopedUsHistogramTimer timer(scopedUsCounter); |
| 75 |
| 45 } // namespace blink | 76 } // namespace blink |
| 46 | 77 |
| 47 #endif // Histogram_h | 78 #endif // Histogram_h |
| OLD | NEW |