| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Histogram is an object that aggregates statistics, and can summarize them in | 5 // Histogram is an object that aggregates statistics, and can summarize them in |
| 6 // various forms, including ASCII graphical, HTML, and numerically (as a | 6 // various forms, including ASCII graphical, HTML, and numerically (as a |
| 7 // vector of numbers corresponding to each of the aggregating buckets). | 7 // vector of numbers corresponding to each of the aggregating buckets). |
| 8 | 8 |
| 9 // It supports calls to accumulate either time intervals (which are processed | 9 // It supports calls to accumulate either time intervals (which are processed |
| 10 // as integral number of milliseconds), or arbitrary integral units. | 10 // as integral number of milliseconds), or arbitrary integral units. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #define HISTOGRAM_COUNTS(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ | 58 #define HISTOGRAM_COUNTS(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ |
| 59 name, sample, 1, 1000000, 50) | 59 name, sample, 1, 1000000, 50) |
| 60 | 60 |
| 61 #define HISTOGRAM_COUNTS_100(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ | 61 #define HISTOGRAM_COUNTS_100(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ |
| 62 name, sample, 1, 100, 50) | 62 name, sample, 1, 100, 50) |
| 63 | 63 |
| 64 #define HISTOGRAM_COUNTS_10000(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ | 64 #define HISTOGRAM_COUNTS_10000(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ |
| 65 name, sample, 1, 10000, 50) | 65 name, sample, 1, 10000, 50) |
| 66 | 66 |
| 67 #define HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \ | 67 #define HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \ |
| 68 static scoped_refptr<base::Histogram> counter = \ | 68 scoped_refptr<base::Histogram> counter = \ |
| 69 base::Histogram::FactoryGet(name, min, max, bucket_count, \ | 69 base::Histogram::FactoryGet(name, min, max, bucket_count, \ |
| 70 base::Histogram::kNoFlags); \ | 70 base::Histogram::kNoFlags); \ |
| 71 DCHECK_EQ(name, counter->histogram_name()); \ | 71 DCHECK_EQ(name, counter->histogram_name()); \ |
| 72 if (counter.get()) counter->Add(sample); \ | 72 if (counter.get()) counter->Add(sample); \ |
| 73 } while (0) | 73 } while (0) |
| 74 | 74 |
| 75 #define HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ | 75 #define HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ |
| 76 HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) | 76 HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) |
| 77 | 77 |
| 78 // For folks that need real specific times, use this to select a precise range | 78 // For folks that need real specific times, use this to select a precise range |
| 79 // of times you want plotted, and the number of buckets you want used. | 79 // of times you want plotted, and the number of buckets you want used. |
| 80 #define HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \ | 80 #define HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \ |
| 81 static scoped_refptr<base::Histogram> counter = \ | 81 scoped_refptr<base::Histogram> counter = \ |
| 82 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ | 82 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ |
| 83 base::Histogram::kNoFlags); \ | 83 base::Histogram::kNoFlags); \ |
| 84 DCHECK_EQ(name, counter->histogram_name()); \ | 84 DCHECK_EQ(name, counter->histogram_name()); \ |
| 85 if (counter.get()) counter->AddTime(sample); \ | 85 if (counter.get()) counter->AddTime(sample); \ |
| 86 } while (0) | 86 } while (0) |
| 87 | 87 |
| 88 // DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES. | 88 // DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES. |
| 89 #define HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \ | 89 #define HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \ |
| 90 static scoped_refptr<base::Histogram> counter = \ | 90 scoped_refptr<base::Histogram> counter = \ |
| 91 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ | 91 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ |
| 92 base::Histogram::kNoFlags); \ | 92 base::Histogram::kNoFlags); \ |
| 93 DCHECK_EQ(name, counter->histogram_name()); \ | 93 DCHECK_EQ(name, counter->histogram_name()); \ |
| 94 if ((sample) < (max) && counter.get()) counter->AddTime(sample); \ | 94 if ((sample) < (max) && counter.get()) counter->AddTime(sample); \ |
| 95 } while (0) | 95 } while (0) |
| 96 | 96 |
| 97 // Support histograming of an enumerated value. The samples should always be | 97 // Support histograming of an enumerated value. The samples should always be |
| 98 // less than boundary_value. | 98 // less than boundary_value. |
| 99 | 99 |
| 100 #define HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ | 100 #define HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ |
| 101 static scoped_refptr<base::Histogram> counter = \ | 101 scoped_refptr<base::Histogram> counter = \ |
| 102 base::LinearHistogram::FactoryGet(name, 1, boundary_value, \ | 102 base::LinearHistogram::FactoryGet(name, 1, boundary_value, \ |
| 103 boundary_value + 1, \ | 103 boundary_value + 1, \ |
| 104 base::Histogram::kNoFlags); \ | 104 base::Histogram::kNoFlags); \ |
| 105 DCHECK_EQ(name, counter->histogram_name()); \ | 105 DCHECK_EQ(name, counter->histogram_name()); \ |
| 106 if (counter.get()) counter->Add(sample); \ | 106 if (counter.get()) counter->Add(sample); \ |
| 107 } while (0) | 107 } while (0) |
| 108 | 108 |
| 109 #define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ | 109 #define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ |
| 110 static scoped_refptr<base::Histogram> counter = \ | 110 scoped_refptr<base::Histogram> counter = \ |
| 111 base::CustomHistogram::FactoryGet(name, custom_ranges, \ | 111 base::CustomHistogram::FactoryGet(name, custom_ranges, \ |
| 112 base::Histogram::kNoFlags); \ | 112 base::Histogram::kNoFlags); \ |
| 113 DCHECK_EQ(name, counter->histogram_name()); \ | 113 DCHECK_EQ(name, counter->histogram_name()); \ |
| 114 if (counter.get()) counter->Add(sample); \ | 114 if (counter.get()) counter->Add(sample); \ |
| 115 } while (0) | 115 } while (0) |
| 116 | 116 |
| 117 | 117 |
| 118 //------------------------------------------------------------------------------ | 118 //------------------------------------------------------------------------------ |
| 119 // Define Debug vs non-debug flavors of macros. | 119 // Define Debug vs non-debug flavors of macros. |
| 120 #ifndef NDEBUG | 120 #ifndef NDEBUG |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 #define UMA_HISTOGRAM_MEDIUM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \ | 164 #define UMA_HISTOGRAM_MEDIUM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \ |
| 165 name, sample, base::TimeDelta::FromMilliseconds(10), \ | 165 name, sample, base::TimeDelta::FromMilliseconds(10), \ |
| 166 base::TimeDelta::FromMinutes(3), 50) | 166 base::TimeDelta::FromMinutes(3), 50) |
| 167 | 167 |
| 168 // Use this macro when times can routinely be much longer than 10 seconds. | 168 // Use this macro when times can routinely be much longer than 10 seconds. |
| 169 #define UMA_HISTOGRAM_LONG_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \ | 169 #define UMA_HISTOGRAM_LONG_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \ |
| 170 name, sample, base::TimeDelta::FromMilliseconds(1), \ | 170 name, sample, base::TimeDelta::FromMilliseconds(1), \ |
| 171 base::TimeDelta::FromHours(1), 50) | 171 base::TimeDelta::FromHours(1), 50) |
| 172 | 172 |
| 173 #define UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \ | 173 #define UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \ |
| 174 static scoped_refptr<base::Histogram> counter = \ | 174 scoped_refptr<base::Histogram> counter = \ |
| 175 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ | 175 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ |
| 176 base::Histogram::kUmaTargetedHistogramFlag); \ | 176 base::Histogram::kUmaTargetedHistogramFlag); \ |
| 177 DCHECK_EQ(name, counter->histogram_name()); \ | 177 DCHECK_EQ(name, counter->histogram_name()); \ |
| 178 if (counter.get()) counter->AddTime(sample); \ | 178 if (counter.get()) counter->AddTime(sample); \ |
| 179 } while (0) | 179 } while (0) |
| 180 | 180 |
| 181 // DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES. | 181 // DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES. |
| 182 #define UMA_HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \ | 182 #define UMA_HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \ |
| 183 static scoped_refptr<base::Histogram> counter = \ | 183 scoped_refptr<base::Histogram> counter = \ |
| 184 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ | 184 base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ |
| 185 base::Histogram::kUmaTargetedHistogramFlag); \ | 185 base::Histogram::kUmaTargetedHistogramFlag); \ |
| 186 DCHECK_EQ(name, counter->histogram_name()); \ | 186 DCHECK_EQ(name, counter->histogram_name()); \ |
| 187 if ((sample) < (max) && counter.get()) counter->AddTime(sample); \ | 187 if ((sample) < (max) && counter.get()) counter->AddTime(sample); \ |
| 188 } while (0) | 188 } while (0) |
| 189 | 189 |
| 190 #define UMA_HISTOGRAM_COUNTS(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ | 190 #define UMA_HISTOGRAM_COUNTS(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
| 191 name, sample, 1, 1000000, 50) | 191 name, sample, 1, 1000000, 50) |
| 192 | 192 |
| 193 #define UMA_HISTOGRAM_COUNTS_100(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ | 193 #define UMA_HISTOGRAM_COUNTS_100(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
| 194 name, sample, 1, 100, 50) | 194 name, sample, 1, 100, 50) |
| 195 | 195 |
| 196 #define UMA_HISTOGRAM_COUNTS_10000(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ | 196 #define UMA_HISTOGRAM_COUNTS_10000(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
| 197 name, sample, 1, 10000, 50) | 197 name, sample, 1, 10000, 50) |
| 198 | 198 |
| 199 #define UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \ | 199 #define UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \ |
| 200 static scoped_refptr<base::Histogram> counter = \ | 200 scoped_refptr<base::Histogram> counter = \ |
| 201 base::Histogram::FactoryGet(name, min, max, bucket_count, \ | 201 base::Histogram::FactoryGet(name, min, max, bucket_count, \ |
| 202 base::Histogram::kUmaTargetedHistogramFlag); \ | 202 base::Histogram::kUmaTargetedHistogramFlag); \ |
| 203 DCHECK_EQ(name, counter->histogram_name()); \ | 203 DCHECK_EQ(name, counter->histogram_name()); \ |
| 204 if (counter.get()) counter->Add(sample); \ | 204 if (counter.get()) counter->Add(sample); \ |
| 205 } while (0) | 205 } while (0) |
| 206 | 206 |
| 207 #define UMA_HISTOGRAM_MEMORY_KB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ | 207 #define UMA_HISTOGRAM_MEMORY_KB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
| 208 name, sample, 1000, 500000, 50) | 208 name, sample, 1000, 500000, 50) |
| 209 | 209 |
| 210 #define UMA_HISTOGRAM_MEMORY_MB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ | 210 #define UMA_HISTOGRAM_MEMORY_MB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
| 211 name, sample, 1, 1000, 50) | 211 name, sample, 1, 1000, 50) |
| 212 | 212 |
| 213 #define UMA_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ | 213 #define UMA_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ |
| 214 UMA_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) | 214 UMA_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) |
| 215 | 215 |
| 216 #define UMA_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ | 216 #define UMA_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ |
| 217 static scoped_refptr<base::Histogram> counter = \ | 217 scoped_refptr<base::Histogram> counter = \ |
| 218 base::LinearHistogram::FactoryGet(name, 1, boundary_value, \ | 218 base::LinearHistogram::FactoryGet(name, 1, boundary_value, \ |
| 219 boundary_value + 1, base::Histogram::kUmaTargetedHistogramFlag); \ | 219 boundary_value + 1, base::Histogram::kUmaTargetedHistogramFlag); \ |
| 220 DCHECK_EQ(name, counter->histogram_name()); \ | 220 DCHECK_EQ(name, counter->histogram_name()); \ |
| 221 if (counter.get()) counter->Add(sample); \ | 221 if (counter.get()) counter->Add(sample); \ |
| 222 } while (0) | 222 } while (0) |
| 223 | 223 |
| 224 #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ | 224 #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ |
| 225 static scoped_refptr<base::Histogram> counter = \ | 225 scoped_refptr<base::Histogram> counter = \ |
| 226 base::CustomHistogram::FactoryGet(name, custom_ranges, \ | 226 base::CustomHistogram::FactoryGet(name, custom_ranges, \ |
| 227 base::Histogram::kUmaTargetedHistogramFlag); \ | 227 base::Histogram::kUmaTargetedHistogramFlag); \ |
| 228 DCHECK_EQ(name, counter->histogram_name()); \ | 228 DCHECK_EQ(name, counter->histogram_name()); \ |
| 229 if (counter.get()) counter->Add(sample); \ | 229 if (counter.get()) counter->Add(sample); \ |
| 230 } while (0) | 230 } while (0) |
| 231 | 231 |
| 232 //------------------------------------------------------------------------------ | 232 //------------------------------------------------------------------------------ |
| 233 | 233 |
| 234 class BooleanHistogram; | 234 class BooleanHistogram; |
| 235 class CustomHistogram; | 235 class CustomHistogram; |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 | 698 |
| 699 // Dump all known histograms to log. | 699 // Dump all known histograms to log. |
| 700 static bool dump_on_exit_; | 700 static bool dump_on_exit_; |
| 701 | 701 |
| 702 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 702 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
| 703 }; | 703 }; |
| 704 | 704 |
| 705 } // namespace base | 705 } // namespace base |
| 706 | 706 |
| 707 #endif // BASE_METRICS_HISTOGRAM_H_ | 707 #endif // BASE_METRICS_HISTOGRAM_H_ |
| OLD | NEW |