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