| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 BASE_METRICS_HISTOGRAM_MACROS_H_ | 5 #ifndef BASE_METRICS_HISTOGRAM_MACROS_H_ |
| 6 #define BASE_METRICS_HISTOGRAM_MACROS_H_ | 6 #define BASE_METRICS_HISTOGRAM_MACROS_H_ |
| 7 | 7 |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/metrics/histogram_macros_internal.h" | 9 #include "base/metrics/histogram_macros_internal.h" |
| 10 #include "base/metrics/histogram_macros_local.h" | 10 #include "base/metrics/histogram_macros_local.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 | 12 |
| 13 |
| 13 // Macros for efficient use of histograms. | 14 // Macros for efficient use of histograms. |
| 14 // | 15 // |
| 15 // For best practices on deciding when to emit to a histogram and what form | 16 // For best practices on deciding when to emit to a histogram and what form |
| 16 // the histogram should take, see tools/metrics/histograms/README.md | 17 // the histogram should take, see tools/metrics/histograms/README.md |
| 17 // | |
| 18 // TODO(nikunjb): Move sparse macros to this file. | |
| 19 // | |
| 20 // UMA_HISTOGRAM_SPARSE_SLOWLY is defined in sparse_histogram.h as it has | |
| 21 // different #include dependencies. | |
| 22 | 18 |
| 23 // TODO(rkaplow): Link to proper documentation on metric creation once we have | 19 // TODO(rkaplow): Link to proper documentation on metric creation once we have |
| 24 // it in a good state. | 20 // it in a good state. |
| 25 | 21 |
| 26 // All of these macros must be called with |name| as a runtime constant - it | 22 // All of these macros must be called with |name| as a runtime constant - it |
| 27 // doesn't have to literally be a constant, but it must be the same string on | 23 // doesn't have to literally be a constant, but it must be the same string on |
| 28 // all calls from a particular call site. If this rule is violated, it is | 24 // all calls from a particular call site. If this rule is violated, it is |
| 29 // possible the data will be written to the wrong histogram. | 25 // possible the data will be written to the wrong histogram. |
| 30 | 26 |
| 31 //------------------------------------------------------------------------------ | 27 //------------------------------------------------------------------------------ |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 bucket_count) \ | 223 bucket_count) \ |
| 228 INTERNAL_HISTOGRAM_CUSTOM_COUNTS_WITH_FLAG( \ | 224 INTERNAL_HISTOGRAM_CUSTOM_COUNTS_WITH_FLAG( \ |
| 229 name, sample, min, max, bucket_count, \ | 225 name, sample, min, max, bucket_count, \ |
| 230 base::HistogramBase::kUmaStabilityHistogramFlag) | 226 base::HistogramBase::kUmaStabilityHistogramFlag) |
| 231 | 227 |
| 232 #define UMA_STABILITY_HISTOGRAM_ENUMERATION(name, sample, enum_max) \ | 228 #define UMA_STABILITY_HISTOGRAM_ENUMERATION(name, sample, enum_max) \ |
| 233 INTERNAL_HISTOGRAM_ENUMERATION_WITH_FLAG( \ | 229 INTERNAL_HISTOGRAM_ENUMERATION_WITH_FLAG( \ |
| 234 name, sample, enum_max, \ | 230 name, sample, enum_max, \ |
| 235 base::HistogramBase::kUmaStabilityHistogramFlag) | 231 base::HistogramBase::kUmaStabilityHistogramFlag) |
| 236 | 232 |
| 233 //------------------------------------------------------------------------------ |
| 234 // Sparse histograms. |
| 235 |
| 236 // Sparse histograms are well suited for recording counts of exact sample values |
| 237 // that are sparsely distributed over a large range. |
| 238 // |
| 239 // UMA_HISTOGRAM_SPARSE_SLOWLY is good for sparsely distributed and/or |
| 240 // infrequently recorded values since the implementation is slower |
| 241 // and takes more memory. |
| 242 // |
| 243 // For instance, Sqlite.Version.* are sparse because for any given database, |
| 244 // there's going to be exactly one version logged. |
| 245 #define UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample) \ |
| 246 INTERNAL_HISTOGRAM_SPARSE_SLOWLY(name, sample) |
| 237 | 247 |
| 238 //------------------------------------------------------------------------------ | 248 //------------------------------------------------------------------------------ |
| 239 // Deprecated histogram macros. Not recommended for current use. | 249 // Deprecated histogram macros. Not recommended for current use. |
| 240 | 250 |
| 241 // Legacy name for UMA_HISTOGRAM_COUNTS_1M. Suggest using explicit naming | 251 // Legacy name for UMA_HISTOGRAM_COUNTS_1M. Suggest using explicit naming |
| 242 // and not using this macro going forward. | 252 // and not using this macro going forward. |
| 243 #define UMA_HISTOGRAM_COUNTS(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ | 253 #define UMA_HISTOGRAM_COUNTS(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
| 244 name, sample, 1, 1000000, 50) | 254 name, sample, 1, 1000000, 50) |
| 245 | 255 |
| 246 // MB-granularity memory metric. This has a short max (1G). | 256 // MB-granularity memory metric. This has a short max (1G). |
| 247 #define UMA_HISTOGRAM_MEMORY_MB(name, sample) \ | 257 #define UMA_HISTOGRAM_MEMORY_MB(name, sample) \ |
| 248 UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 1000, 50) | 258 UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 1000, 50) |
| 249 | 259 |
| 250 // For an enum with customized range. In general, sparse histograms should be | 260 // For an enum with customized range. In general, sparse histograms should be |
| 251 // used instead. | 261 // used instead. |
| 252 // Samples should be one of the std::vector<int> list provided via | 262 // Samples should be one of the std::vector<int> list provided via |
| 253 // |custom_ranges|. See comments above CustomRanges::FactoryGet about the | 263 // |custom_ranges|. See comments above CustomRanges::FactoryGet about the |
| 254 // requirement of |custom_ranges|. You can use the helper function | 264 // requirement of |custom_ranges|. You can use the helper function |
| 255 // CustomHistogram::ArrayToCustomRanges to transform a C-style array of valid | 265 // CustomHistogram::ArrayToCustomRanges to transform a C-style array of valid |
| 256 // sample values to a std::vector<int>. | 266 // sample values to a std::vector<int>. |
| 257 #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ | 267 #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ |
| 258 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \ | 268 STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \ |
| 259 base::CustomHistogram::FactoryGet(name, custom_ranges, \ | 269 base::CustomHistogram::FactoryGet(name, custom_ranges, \ |
| 260 base::HistogramBase::kUmaTargetedHistogramFlag)) | 270 base::HistogramBase::kUmaTargetedHistogramFlag)) |
| 261 | 271 |
| 262 #endif // BASE_METRICS_HISTOGRAM_MACROS_H_ | 272 #endif // BASE_METRICS_HISTOGRAM_MACROS_H_ |
| OLD | NEW |