Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_BASE_HISTOGRAM_MACROS_H_ | |
| 6 #define CC_BASE_HISTOGRAM_MACROS_H_ | |
| 7 | |
| 8 #include <limits> | |
| 9 | |
| 10 #include "base/metrics/histogram_macros.h" | |
| 11 #include "base/numerics/safe_math.h" | |
| 12 #include "base/timer/elapsed_timer.h" | |
| 13 | |
| 14 // Emits UMA histogram trackers for time spent as well as area (in pixels) | |
| 15 // processed per unit time. Time is measured in microseconds, and work in | |
| 16 // 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
| |
| 17 // | |
| 18 // Usage: | |
| 19 // // Outside of a method, perhaps in a namespace. | |
| 20 // DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(ScopedReticulateSplinesTimer, | |
| 21 // "ReticulateSplinesUs", | |
| 22 // "ReticulateSplinesPixelsPerMs"); | |
| 23 // | |
| 24 // // Inside a method. | |
| 25 // ScopedReticulateSplinesTimer timer; | |
| 26 // timer.AddArea(some_rect.size().GetArea()); | |
| 27 #define DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(class_name, time_histogram, \ | |
| 28 area_histogram) \ | |
| 29 class class_name { \ | |
| 30 public: \ | |
| 31 class_name(); \ | |
| 32 ~class_name(); \ | |
| 33 void AddArea(int area) { area_ += area; } \ | |
| 34 void SetArea(int area) { area_ = area; } \ | |
| 35 \ | |
| 36 private: \ | |
| 37 base::ElapsedTimer timer_; \ | |
| 38 base::CheckedNumeric<int> area_; \ | |
| 39 }; \ | |
| 40 class_name::class_name() : area_(0) {} \ | |
| 41 class_name::~class_name() { \ | |
| 42 base::TimeDelta elapsed = timer_.Elapsed(); \ | |
| 43 int area = area_.ValueOrDefault(std::numeric_limits<int>::max()); \ | |
| 44 UMA_HISTOGRAM_COUNTS(time_histogram, elapsed.InMicroseconds()); \ | |
| 45 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
| |
| 46 } | |
| 47 | |
| 48 #endif // CC_BASE_HISTOGRAM_MACROS_H_ | |
| OLD | NEW |