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

Unified Diff: ui/events/event.cc

Issue 1829973002: Cache pointers to histograms for recording event times. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« base/metrics/histogram_macros.h ('K') | « base/metrics/histogram_macros.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/event.cc
diff --git a/ui/events/event.cc b/ui/events/event.cc
index ca6704b6f8fa5b6e49888074b799c620b7bc90e2..b29c68daa83397fa9ffd6a4349c192f9d1f44c46 100644
--- a/ui/events/event.cc
+++ b/ui/events/event.cc
@@ -312,16 +312,17 @@ Event::Event(const base::NativeEvent& native_event,
static_cast<base::HistogramBase::Sample>(delta.InMicroseconds());
UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser", delta_sample, 1, 1000000,
100);
- std::string name_for_event =
- base::StringPrintf("Event.Latency.Browser.%s", name_.c_str());
- base::HistogramBase* counter_for_type =
+
+ // Though it seems inefficient to generate the string twice, the first
+ // instance will be used only for DCHECK builds and the second won't be
+ // executed at all if the histogram was previously accessed here.
+ STATIC_HISTOGRAM_POINTER_GROUP(
+ base::StringPrintf("Event.Latency.Browser.%s", name_.c_str()),
+ type_, ET_LAST, Add(delta_sample),
base::Histogram::FactoryGet(
- name_for_event,
- 1,
- 1000000,
- 100,
- base::HistogramBase::kUmaTargetedHistogramFlag);
- counter_for_type->Add(delta_sample);
+ base::StringPrintf("Event.Latency.Browser.%s", name_.c_str()),
+ 1, 1000000, 100,
+ base::HistogramBase::kUmaTargetedHistogramFlag));
#if defined(USE_X11)
if (native_event->type == GenericEvent) {
« base/metrics/histogram_macros.h ('K') | « base/metrics/histogram_macros.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698