Chromium Code Reviews| 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() * base::Time::kMicrosec ondsPerSecond), | |
|
Alexei Svitkine (slow)
2016/04/01 16:39:04
Nit: Why not just do the multiplication on the del
chrishtr
2016/04/01 16:43:44
Done. Good idea.
| |
| 51 m_counter(counter) {} | |
| 52 | |
| 53 ~ScopedUsHistogramTimer() | |
| 54 { | |
| 55 m_counter.count(WTF::monotonicallyIncreasingTime() * base::Time::kMicros econdsPerSecond - m_startTime); | |
| 56 } | |
| 57 | |
| 58 private: | |
| 59 // In microseconds. | |
| 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. | |
|
Alexei Svitkine (slow)
2016/04/01 16:39:04
Expand comment to mention that this macro shouldn'
chrishtr
2016/04/01 16:43:44
Done.
| |
| 71 #define SCOPED_BLINK_UMA_HISTOGRAM_TIMER(name) \ | |
| 72 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounter, (name, 0, 10000000, 5 0)); \ | |
| 73 ScopedUsHistogramTimer timer(scopedUsCounter); | |
| 74 | |
| 45 } // namespace blink | 75 } // namespace blink |
| 46 | 76 |
| 47 #endif // Histogram_h | 77 #endif // Histogram_h |
| OLD | NEW |