Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Unified Diff: base/metrics/histogram_macros.h

Issue 920963003: Moved scoped_histogram_timer to the main histogram_macros.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove gyp entries for old unit test in media/ Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/base.gyp ('k') | base/metrics/histogram_macros_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_macros.h
diff --git a/base/metrics/histogram_macros.h b/base/metrics/histogram_macros.h
index e9a871c358f71860f8314cd4510eb3bab6285132..87e0338dea369a43d671aab044c04eafd2062dcc 100644
--- a/base/metrics/histogram_macros.h
+++ b/base/metrics/histogram_macros.h
@@ -229,4 +229,25 @@
base::CustomHistogram::FactoryGet(name, custom_ranges, \
base::HistogramBase::kUmaTargetedHistogramFlag))
+// Scoped class which logs its time on this earth as a UMA statistic. Must be
+// a #define macro since UMA macros prevent variables as names. The nested
+// macro is necessary to expand __COUNTER__ to an actual value.
+#define SCOPED_UMA_HISTOGRAM_TIMER(name) \
+ SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, __COUNTER__)
+
+#define SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, key) \
+ SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key)
+
+#define SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key) \
+ class ScopedHistogramTimer##key { \
+ public: \
+ ScopedHistogramTimer##key() : constructed_(base::TimeTicks::Now()) {} \
+ ~ScopedHistogramTimer##key() { \
+ base::TimeDelta elapsed = base::TimeTicks::Now() - constructed_; \
+ UMA_HISTOGRAM_TIMES(name, elapsed); \
+ } \
+ private: \
+ base::TimeTicks constructed_; \
+ } scoped_histogram_timer_##key
+
#endif // BASE_METRICS_HISTOGRAM_MACROS_H_
« no previous file with comments | « base/base.gyp ('k') | base/metrics/histogram_macros_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698