Chromium Code Reviews| Index: third_party/WebKit/Source/platform/Histogram.h |
| diff --git a/third_party/WebKit/Source/platform/Histogram.h b/third_party/WebKit/Source/platform/Histogram.h |
| index a88970454c9e2ff4dce33c2774f81081f6fcc363..05879a4abdfb370835fff2c44828726c5b9edd95 100644 |
| --- a/third_party/WebKit/Source/platform/Histogram.h |
| +++ b/third_party/WebKit/Source/platform/Histogram.h |
| @@ -7,6 +7,7 @@ |
| #include "base/metrics/histogram_base.h" |
| #include "platform/PlatformExport.h" |
| +#include "wtf/CurrentTime.h" |
| #include <stdint.h> |
| namespace base { |
| @@ -23,7 +24,6 @@ public: |
| protected: |
| explicit CustomCountHistogram(base::HistogramBase*); |
| -private: |
| base::HistogramBase* m_histogram; |
| }; |
| @@ -42,6 +42,36 @@ private: |
| base::HistogramBase* m_histogram; |
| }; |
| + |
| + |
| +class PLATFORM_EXPORT ScopedUsHistogramTimer { |
| +public: |
| + ScopedUsHistogramTimer(CustomCountHistogram& counter) |
| + : m_startTime(WTF::monotonicallyIncreasingTime() * base::Time::kMicrosecondsPerSecond), |
|
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.
|
| + m_counter(counter) {} |
| + |
| + ~ScopedUsHistogramTimer() |
| + { |
| + m_counter.count(WTF::monotonicallyIncreasingTime() * base::Time::kMicrosecondsPerSecond - m_startTime); |
| + } |
| + |
| +private: |
| + // In microseconds. |
| + double m_startTime; |
| + CustomCountHistogram& m_counter; |
| +}; |
| + |
| +// Use code like this to record time, in microseconds, to execute a block of code: |
| +// |
| +// { |
| +// SCOPED_BLINK_UMA_HISTOGRAM_TIMER(myUmaStatName) |
| +// RunMyCode(); |
| +// } |
| +// 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.
|
| +#define SCOPED_BLINK_UMA_HISTOGRAM_TIMER(name) \ |
| +DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounter, (name, 0, 10000000, 50)); \ |
| +ScopedUsHistogramTimer timer(scopedUsCounter); |
| + |
| } // namespace blink |
| #endif // Histogram_h |