Chromium Code Reviews| Index: media/base/scoped_histogram_timer.h |
| diff --git a/media/base/scoped_histogram_timer.h b/media/base/scoped_histogram_timer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..728e49f815359eece7ec66af77aaf311f766eabf |
| --- /dev/null |
| +++ b/media/base/scoped_histogram_timer.h |
| @@ -0,0 +1,31 @@ |
| +// Copyright 2013 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 MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_ |
| +#define MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_ |
| + |
| +#include "base/metrics/histogram.h" |
| +#include "base/time.h" |
| + |
| +// Scoped class which logs its time on this earth as a UMA statistic. Must be |
| +// a #define macro since UMA macros prevent variables as names. The nested |
| +// macro is necessary to expand __COUNTER__ to an actual value. |
| +#define SCOPED_UMA_HISTOGRAM_TIMER(name) \ |
| + SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, __COUNTER__) |
| + |
| +#define SCOPED_UMA_HISTOGRAM_TIMER_EXPANDER(name, key) \ |
| + SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key) |
| + |
| +#define SCOPED_UMA_HISTOGRAM_TIMER_UNIQUE(name, key) \ |
| + class ScopedHistogramTimer##key { \ |
| + public: \ |
| + ScopedHistogramTimer##key() : constructed_(base::TimeTicks::Now()) {} \ |
| + ~ScopedHistogramTimer##key() { \ |
| + UMA_HISTOGRAM_TIMES(name, base::TimeTicks::Now() - constructed_); \ |
|
Alexei Svitkine (slow)
2013/05/14 15:55:43
Please extract base::TimeTicks::Now() - contructed
jar (doing other things)
2013/05/14 16:19:22
Good suggestion. In this case the given arg is th
DaleCurtis
2013/05/15 01:30:31
Done.
|
| + } \ |
| + private: \ |
| + base::TimeTicks constructed_; \ |
| + } scoped_histogram_timer_##key |
| + |
| +#endif // MEDIA_BASE_SCOPED_HISTOGRAM_TIMER_H_ |