Video Player: Enable chromecast support by default
[chromium-blink-merge.git] / media / base / scoped_histogram_timer.h
bloba7f69b0ab9b41044e47925db0c5f970c51f035f6
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_
6 #define MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_
8 #include "base/metrics/histogram.h"
9 #include "base/time/time.h"
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
13 // macro is necessary to expand __COUNTER__ to an actual value.
14 #define SCOPED_UMA_HISTOGRAM_TIMER(name) \
15 SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, __COUNTER__)
17 #define SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, key) \
18 SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key)
20 #define SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key) \
21 class ScopedHistogramTimer##key { \
22 public: \
23 ScopedHistogramTimer##key() : constructed_(base::TimeTicks::Now()) {} \
24 ~ScopedHistogramTimer##key() { \
25 base::TimeDelta elapsed = base::TimeTicks::Now() - constructed_; \
26 UMA_HISTOGRAM_TIMES(name, elapsed); \
27 } \
28 private: \
29 base::TimeTicks constructed_; \
30 } scoped_histogram_timer_##key
32 #endif // MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_