webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
histogram_macros.h
Go to the documentation of this file.
1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // histogram_macros.h:
7 // Helpers for making histograms, to keep consistency with Chromium's
8 // histogram_macros.h.
9 
10 #ifndef LIBANGLE_HISTOGRAM_MACROS_H_
11 #define LIBANGLE_HISTOGRAM_MACROS_H_
12 
13 #include <platform/Platform.h>
14 
15 #define ANGLE_HISTOGRAM_TIMES(name, sample) ANGLE_HISTOGRAM_CUSTOM_TIMES( \
16  name, sample, 1, 10000, 50)
17 
18 #define ANGLE_HISTOGRAM_MEDIUM_TIMES(name, sample) ANGLE_HISTOGRAM_CUSTOM_TIMES( \
19  name, sample, 10, 180000, 50)
20 
21 // Use this macro when times can routinely be much longer than 10 seconds.
22 #define ANGLE_HISTOGRAM_LONG_TIMES(name, sample) ANGLE_HISTOGRAM_CUSTOM_TIMES( \
23  name, sample, 1, 3600000, 50)
24 
25 // Use this macro when times can routinely be much longer than 10 seconds and
26 // you want 100 buckets.
27 #define ANGLE_HISTOGRAM_LONG_TIMES_100(name, sample) ANGLE_HISTOGRAM_CUSTOM_TIMES( \
28  name, sample, 1, 3600000, 100)
29 
30 // For folks that need real specific times, use this to select a precise range
31 // of times you want plotted, and the number of buckets you want used.
32 #define ANGLE_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \
33  ANGLE_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count)
34 
35 #define ANGLE_HISTOGRAM_COUNTS(name, sample) ANGLE_HISTOGRAM_CUSTOM_COUNTS( \
36  name, sample, 1, 1000000, 50)
37 
38 #define ANGLE_HISTOGRAM_COUNTS_100(name, sample) \
39  ANGLE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 100, 50)
40 
41 #define ANGLE_HISTOGRAM_COUNTS_10000(name, sample) \
42  ANGLE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 10000, 50)
43 
44 #define ANGLE_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \
45  ANGLEPlatformCurrent()->histogramCustomCounts(\
46  name, sample, min, max, bucket_count)
47 
48 #define ANGLE_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \
49  ANGLE_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101)
50 
51 #define ANGLE_HISTOGRAM_BOOLEAN(name, sample) \
52  ANGLEPlatformCurrent()->histogramBoolean(name, sample)
53 
54 #define ANGLE_HISTOGRAM_ENUMERATION(name, sample, boundary_value) \
55  ANGLEPlatformCurrent()->histogramEnumeration(name, sample, boundary_value)
56 
57 #define ANGLE_HISTOGRAM_MEMORY_KB(name, sample) ANGLE_HISTOGRAM_CUSTOM_COUNTS( \
58  name, sample, 1000, 500000, 50)
59 
60 #define ANGLE_HISTOGRAM_MEMORY_MB(name, sample) ANGLE_HISTOGRAM_CUSTOM_COUNTS( \
61  name, sample, 1, 1000, 50)
62 
63 #define ANGLE_HISTOGRAM_SPARSE_SLOWLY(name, sample) \
64  ANGLEPlatformCurrent()->histogramSparse(name, sample)
65 
66 // Scoped class which logs its time on this earth as a UMA statistic. This is
67 // recommended for when you want a histogram which measures the time it takes
68 // for a method to execute. This measures up to 10 seconds.
69 #define SCOPED_ANGLE_HISTOGRAM_TIMER(name) \
70  SCOPED_ANGLE_HISTOGRAM_TIMER_EXPANDER(name, false, __COUNTER__)
71 
72 // Similar scoped histogram timer, but this uses ANGLE_HISTOGRAM_LONG_TIMES_100,
73 // which measures up to an hour, and uses 100 buckets. This is more expensive
74 // to store, so only use if this often takes >10 seconds.
75 #define SCOPED_ANGLE_HISTOGRAM_LONG_TIMER(name) \
76  SCOPED_ANGLE_HISTOGRAM_TIMER_EXPANDER(name, true, __COUNTER__)
77 
78 // This nested macro is necessary to expand __COUNTER__ to an actual value.
79 #define SCOPED_ANGLE_HISTOGRAM_TIMER_EXPANDER(name, is_long, key) \
80  SCOPED_ANGLE_HISTOGRAM_TIMER_UNIQUE(name, is_long, key)
81 
82 #define SCOPED_ANGLE_HISTOGRAM_TIMER_UNIQUE(name, is_long, key) \
83  class ScopedHistogramTimer##key \
84  { \
85  public: \
86  ScopedHistogramTimer##key() : constructed_(ANGLEPlatformCurrent()->currentTime()) {} \
87  ~ScopedHistogramTimer##key() \
88  { \
89  if (constructed_ == 0) \
90  return; \
91  double elapsed = ANGLEPlatformCurrent()->currentTime() - constructed_; \
92  int elapsedMS = static_cast<int>(elapsed * 1000.0); \
93  if (is_long) \
94  { \
95  ANGLE_HISTOGRAM_LONG_TIMES_100(name, elapsedMS); \
96  } \
97  else \
98  { \
99  ANGLE_HISTOGRAM_TIMES(name, elapsedMS); \
100  } \
101  } \
102  \
103  private: \
104  double constructed_; \
105  } scoped_histogram_timer_##key
106 
107 #endif // BASE_METRICS_HISTOGRAM_MACROS_H_