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

Unified Diff: cc/base/histogram_macros.h

Issue 1075523002: cc: Add UMA stats for record and raster time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix histograms.xml Created 5 years, 8 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
Index: cc/base/histogram_macros.h
diff --git a/cc/base/histogram_macros.h b/cc/base/histogram_macros.h
new file mode 100644
index 0000000000000000000000000000000000000000..0f5b71a4e65d599b915c356d2a1d7cf6890c44fb
--- /dev/null
+++ b/cc/base/histogram_macros.h
@@ -0,0 +1,48 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_BASE_HISTOGRAM_MACROS_H_
+#define CC_BASE_HISTOGRAM_MACROS_H_
+
+#include <limits>
+
+#include "base/metrics/histogram_macros.h"
+#include "base/numerics/safe_math.h"
+#include "base/timer/elapsed_timer.h"
+
+// Emits UMA histogram trackers for time spent as well as area (in pixels)
+// processed per unit time. Time is measured in microseconds, and work in
+// pixels per millisecond.
chrishtr 2015/04/10 17:41:39 Why the difference in time units?
jbroman 2015/04/13 19:34:00 Time would have been in milliseconds, but UMA reco
+//
+// Usage:
+// // Outside of a method, perhaps in a namespace.
+// DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(ScopedReticulateSplinesTimer,
+// "ReticulateSplinesUs",
+// "ReticulateSplinesPixelsPerMs");
+//
+// // Inside a method.
+// ScopedReticulateSplinesTimer timer;
+// timer.AddArea(some_rect.size().GetArea());
+#define DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(class_name, time_histogram, \
+ area_histogram) \
+ class class_name { \
+ public: \
+ class_name(); \
+ ~class_name(); \
+ void AddArea(int area) { area_ += area; } \
+ void SetArea(int area) { area_ = area; } \
+ \
+ private: \
+ base::ElapsedTimer timer_; \
+ base::CheckedNumeric<int> area_; \
+ }; \
+ class_name::class_name() : area_(0) {} \
+ class_name::~class_name() { \
+ base::TimeDelta elapsed = timer_.Elapsed(); \
+ int area = area_.ValueOrDefault(std::numeric_limits<int>::max()); \
+ UMA_HISTOGRAM_COUNTS(time_histogram, elapsed.InMicroseconds()); \
+ UMA_HISTOGRAM_COUNTS(area_histogram, area / elapsed.InMillisecondsF()); \
chrishtr 2015/04/10 17:41:39 Protect against divide by zero?
jbroman 2015/04/13 19:33:59 Euh, the division is defined, but I forgot that th
+ }
+
+#endif // CC_BASE_HISTOGRAM_MACROS_H_
« no previous file with comments | « cc/base/BUILD.gn ('k') | cc/cc.gyp » ('j') | cc/resources/display_list_recording_source.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698