diff options
-rw-r--r-- | base/metrics/histogram_macros.h | 27 | ||||
-rw-r--r-- | base/metrics/histogram_macros_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main.cc | 2 | ||||
-rw-r--r-- | tools/metrics/histograms/histograms.xml | 12 |
4 files changed, 34 insertions, 9 deletions
diff --git a/base/metrics/histogram_macros.h b/base/metrics/histogram_macros.h index 87e0338..2aee1a5 100644 --- a/base/metrics/histogram_macros.h +++ b/base/metrics/histogram_macros.h @@ -229,22 +229,33 @@ 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. +// Scoped class which logs its time on this earth as a UMA statistic. This is +// recommended for when you want a histogram which measures the time it takes +// for a method to execute. This measures up to 10 seconds. #define SCOPED_UMA_HISTOGRAM_TIMER(name) \ - SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, __COUNTER__) + SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, false, __COUNTER__) -#define SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, key) \ - SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key) +// Similar scoped histogram timer, but this uses UMA_HISTOGRAM_LONG_TIMES_100, +// which measures up to an hour, and uses 100 buckets. This is more expensive +// to store, so only use if this often takes >10 seconds. +#define SCOPED_UMA_HISTOGRAM_LONG_TIMER(name) \ + SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, true, __COUNTER__) -#define SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key) \ +// This nested macro is necessary to expand __COUNTER__ to an actual value. +#define SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, is_long, key) \ + SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, is_long, key) + +#define SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, is_long, 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); \ + if (is_long) { \ + UMA_HISTOGRAM_LONG_TIMES_100(name, elapsed); \ + } else { \ + UMA_HISTOGRAM_TIMES(name, elapsed); \ + } \ } \ private: \ base::TimeTicks constructed_; \ diff --git a/base/metrics/histogram_macros_unittest.cc b/base/metrics/histogram_macros_unittest.cc index 94b2a0d..c599161 100644 --- a/base/metrics/histogram_macros_unittest.cc +++ b/base/metrics/histogram_macros_unittest.cc @@ -11,6 +11,8 @@ namespace base { TEST(ScopedHistogramTimer, TwoTimersOneScope) { SCOPED_UMA_HISTOGRAM_TIMER("TestTimer0"); SCOPED_UMA_HISTOGRAM_TIMER("TestTimer1"); + SCOPED_UMA_HISTOGRAM_LONG_TIMER("TestLongTimer0"); + SCOPED_UMA_HISTOGRAM_LONG_TIMER("TestLongTimer1"); } } // namespace base diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index 69ccdf4..5dced63 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -1112,7 +1112,7 @@ void ChromeBrowserMainParts::PostBrowserStart() { int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); - SCOPED_UMA_HISTOGRAM_TIMER("Startup.PreMainMessageLoopRunImplTime"); + SCOPED_UMA_HISTOGRAM_LONG_TIMER("Startup.PreMainMessageLoopRunImplLongTime"); // Android updates the metrics service dynamically depending on whether the // application is in the foreground or not. Do not start here. #if !defined(OS_ANDROID) diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index c5dbf18..a039bb1 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -37130,7 +37130,19 @@ Therefore, the affected-histogram name has to have at least one dot in it. </summary> </histogram> +<histogram name="Startup.PreMainMessageLoopRunImplLongTime" + units="milliseconds"> + <owner>rkaplow@chromium.org</owner> + <summary> + The amount of time that elapsed during + ChromeBrowserMainParts::PreMainMessageLoopRunImpl. + </summary> +</histogram> + <histogram name="Startup.PreMainMessageLoopRunImplTime" units="milliseconds"> + <obsolete> + Deprecated as of 2/2015. + </obsolete> <owner>rkaplow@chromium.org</owner> <summary> The amount of time that elapsed during |