OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_ | 5 #ifndef MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_ |
6 #define MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_ | 6 #define MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_ |
7 | 7 |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/time.h" | 9 #include "base/time/time.h" |
10 | 10 |
11 // Scoped class which logs its time on this earth as a UMA statistic. Must be | 11 // Scoped class which logs its time on this earth as a UMA statistic. Must be |
12 // a #define macro since UMA macros prevent variables as names. The nested | 12 // a #define macro since UMA macros prevent variables as names. The nested |
13 // macro is necessary to expand __COUNTER__ to an actual value. | 13 // macro is necessary to expand __COUNTER__ to an actual value. |
14 #define SCOPED_UMA_HISTOGRAM_TIMER(name) \ | 14 #define SCOPED_UMA_HISTOGRAM_TIMER(name) \ |
15 SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, __COUNTER__) | 15 SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, __COUNTER__) |
16 | 16 |
17 #define SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, key) \ | 17 #define SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, key) \ |
18 SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key) | 18 SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key) |
19 | 19 |
20 #define SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key) \ | 20 #define SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key) \ |
21 class ScopedHistogramTimer##key { \ | 21 class ScopedHistogramTimer##key { \ |
22 public: \ | 22 public: \ |
23 ScopedHistogramTimer##key() : constructed_(base::TimeTicks::Now()) {} \ | 23 ScopedHistogramTimer##key() : constructed_(base::TimeTicks::Now()) {} \ |
24 ~ScopedHistogramTimer##key() { \ | 24 ~ScopedHistogramTimer##key() { \ |
25 base::TimeDelta elapsed = base::TimeTicks::Now() - constructed_; \ | 25 base::TimeDelta elapsed = base::TimeTicks::Now() - constructed_; \ |
26 UMA_HISTOGRAM_TIMES(name, elapsed); \ | 26 UMA_HISTOGRAM_TIMES(name, elapsed); \ |
27 } \ | 27 } \ |
28 private: \ | 28 private: \ |
29 base::TimeTicks constructed_; \ | 29 base::TimeTicks constructed_; \ |
30 } scoped_histogram_timer_##key | 30 } scoped_histogram_timer_##key |
31 | 31 |
32 #endif // MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_ | 32 #endif // MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_ |
OLD | NEW |