| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 // Support histograming of an enumerated value. The samples should always be | 84 // Support histograming of an enumerated value. The samples should always be |
| 85 // less than boundary_value. | 85 // less than boundary_value. |
| 86 | 86 |
| 87 #define HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ | 87 #define HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ |
| 88 static scoped_refptr<Histogram> counter = LinearHistogram::FactoryGet( \ | 88 static scoped_refptr<Histogram> counter = LinearHistogram::FactoryGet( \ |
| 89 name, 1, boundary_value, boundary_value + 1, Histogram::kNoFlags); \ | 89 name, 1, boundary_value, boundary_value + 1, Histogram::kNoFlags); \ |
| 90 counter->Add(sample); \ | 90 counter->Add(sample); \ |
| 91 } while (0) | 91 } while (0) |
| 92 | 92 |
| 93 #define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ |
| 94 static scoped_refptr<Histogram> counter = CustomHistogram::FactoryGet( \ |
| 95 name, custom_ranges, Histogram::kNoFlags); \ |
| 96 counter->Add(sample); \ |
| 97 } while (0) |
| 98 |
| 93 | 99 |
| 94 //------------------------------------------------------------------------------ | 100 //------------------------------------------------------------------------------ |
| 95 // Define Debug vs non-debug flavors of macros. | 101 // Define Debug vs non-debug flavors of macros. |
| 96 #ifndef NDEBUG | 102 #ifndef NDEBUG |
| 97 | 103 |
| 98 #define DHISTOGRAM_TIMES(name, sample) HISTOGRAM_TIMES(name, sample) | 104 #define DHISTOGRAM_TIMES(name, sample) HISTOGRAM_TIMES(name, sample) |
| 99 #define DHISTOGRAM_COUNTS(name, sample) HISTOGRAM_COUNTS(name, sample) | 105 #define DHISTOGRAM_COUNTS(name, sample) HISTOGRAM_COUNTS(name, sample) |
| 100 #define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) HISTOGRAM_PERCENTAGE(\ | 106 #define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) HISTOGRAM_PERCENTAGE(\ |
| 101 name, under_one_hundred) | 107 name, under_one_hundred) |
| 102 #define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ | 108 #define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ |
| 103 HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) | 109 HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) |
| 104 #define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \ | 110 #define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \ |
| 105 HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) | 111 HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) |
| 106 #define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ | 112 #define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ |
| 107 HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) | 113 HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) |
| 108 #define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) \ | 114 #define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) \ |
| 109 HISTOGRAM_ENUMERATION(name, sample, boundary_value) | 115 HISTOGRAM_ENUMERATION(name, sample, boundary_value) |
| 116 #define DHISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ |
| 117 HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) |
| 110 | 118 |
| 111 #else // NDEBUG | 119 #else // NDEBUG |
| 112 | 120 |
| 113 #define DHISTOGRAM_TIMES(name, sample) do {} while (0) | 121 #define DHISTOGRAM_TIMES(name, sample) do {} while (0) |
| 114 #define DHISTOGRAM_COUNTS(name, sample) do {} while (0) | 122 #define DHISTOGRAM_COUNTS(name, sample) do {} while (0) |
| 115 #define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) do {} while (0) | 123 #define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) do {} while (0) |
| 116 #define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ | 124 #define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ |
| 117 do {} while (0) | 125 do {} while (0) |
| 118 #define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \ | 126 #define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \ |
| 119 do {} while (0) | 127 do {} while (0) |
| 120 #define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ | 128 #define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ |
| 121 do {} while (0) | 129 do {} while (0) |
| 122 #define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) do {} while (0) | 130 #define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) do {} while (0) |
| 131 #define DHISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ |
| 132 do {} while (0) |
| 123 | 133 |
| 124 #endif // NDEBUG | 134 #endif // NDEBUG |
| 125 | 135 |
| 126 //------------------------------------------------------------------------------ | 136 //------------------------------------------------------------------------------ |
| 127 // The following macros provide typical usage scenarios for callers that wish | 137 // The following macros provide typical usage scenarios for callers that wish |
| 128 // to record histogram data, and have the data submitted/uploaded via UMA. | 138 // to record histogram data, and have the data submitted/uploaded via UMA. |
| 129 // Not all systems support such UMA, but if they do, the following macros | 139 // Not all systems support such UMA, but if they do, the following macros |
| 130 // should work with the service. | 140 // should work with the service. |
| 131 | 141 |
| 132 #define UMA_HISTOGRAM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \ | 142 #define UMA_HISTOGRAM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \ |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 #define UMA_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ | 189 #define UMA_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ |
| 180 UMA_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) | 190 UMA_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) |
| 181 | 191 |
| 182 #define UMA_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ | 192 #define UMA_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ |
| 183 static scoped_refptr<Histogram> counter = LinearHistogram::FactoryGet( \ | 193 static scoped_refptr<Histogram> counter = LinearHistogram::FactoryGet( \ |
| 184 name, 1, boundary_value, boundary_value + 1, \ | 194 name, 1, boundary_value, boundary_value + 1, \ |
| 185 Histogram::kUmaTargetedHistogramFlag); \ | 195 Histogram::kUmaTargetedHistogramFlag); \ |
| 186 counter->Add(sample); \ | 196 counter->Add(sample); \ |
| 187 } while (0) | 197 } while (0) |
| 188 | 198 |
| 199 #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ |
| 200 static scoped_refptr<Histogram> counter = CustomHistogram::FactoryGet( \ |
| 201 name, custom_ranges, Histogram::kUmaTargetedHistogramFlag); \ |
| 202 counter->Add(sample); \ |
| 203 } while (0) |
| 189 | 204 |
| 190 //------------------------------------------------------------------------------ | 205 //------------------------------------------------------------------------------ |
| 191 | 206 |
| 192 class Pickle; | 207 class BooleanHistogram; |
| 208 class CustomHistogram; |
| 193 class Histogram; | 209 class Histogram; |
| 194 class LinearHistogram; | 210 class LinearHistogram; |
| 195 class BooleanHistogram; | 211 class Pickle; |
| 196 | 212 |
| 197 namespace disk_cache { | 213 namespace disk_cache { |
| 198 class StatsHistogram; | 214 class StatsHistogram; |
| 199 }; // namespace disk_cache | 215 }; // namespace disk_cache |
| 200 | 216 |
| 201 | 217 |
| 202 class Histogram : public base::RefCountedThreadSafe<Histogram> { | 218 class Histogram : public base::RefCountedThreadSafe<Histogram> { |
| 203 public: | 219 public: |
| 204 typedef int Sample; // Used for samples (and ranges of samples). | 220 typedef int Sample; // Used for samples (and ranges of samples). |
| 205 typedef int Count; // Used to count samples in a bucket. | 221 typedef int Count; // Used to count samples in a bucket. |
| 206 static const Sample kSampleType_MAX = INT_MAX; | 222 static const Sample kSampleType_MAX = INT_MAX; |
| 207 | 223 |
| 208 typedef std::vector<Count> Counts; | 224 typedef std::vector<Count> Counts; |
| 209 typedef std::vector<Sample> Ranges; | 225 typedef std::vector<Sample> Ranges; |
| 210 | 226 |
| 211 /* These enums are meant to facilitate deserialization of renderer histograms | 227 /* These enums are meant to facilitate deserialization of renderer histograms |
| 212 into the browser. */ | 228 into the browser. */ |
| 213 enum ClassType { | 229 enum ClassType { |
| 214 HISTOGRAM, | 230 HISTOGRAM, |
| 215 LINEAR_HISTOGRAM, | 231 LINEAR_HISTOGRAM, |
| 216 BOOLEAN_HISTOGRAM, | 232 BOOLEAN_HISTOGRAM, |
| 233 CUSTOM_HISTOGRAM, |
| 217 NOT_VALID_IN_RENDERER | 234 NOT_VALID_IN_RENDERER |
| 218 }; | 235 }; |
| 219 | 236 |
| 220 enum BucketLayout { | 237 enum BucketLayout { |
| 221 EXPONENTIAL, | 238 EXPONENTIAL, |
| 222 LINEAR | 239 LINEAR, |
| 240 CUSTOM |
| 223 }; | 241 }; |
| 224 | 242 |
| 225 enum Flags { | 243 enum Flags { |
| 226 kNoFlags = 0, | 244 kNoFlags = 0, |
| 227 kUmaTargetedHistogramFlag = 0x1, // Histogram should be UMA uploaded. | 245 kUmaTargetedHistogramFlag = 0x1, // Histogram should be UMA uploaded. |
| 228 | 246 |
| 229 // Indicate that the histogram was pickled to be sent across an IPC Channel. | 247 // Indicate that the histogram was pickled to be sent across an IPC Channel. |
| 230 // If we observe this flag on a histogram being aggregated into after IPC, | 248 // If we observe this flag on a histogram being aggregated into after IPC, |
| 231 // then we are running in a single process mode, and the aggregation should | 249 // then we are running in a single process mode, and the aggregation should |
| 232 // not take place (as we would be aggregating back into the source | 250 // not take place (as we would be aggregating back into the source |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 base::TimeDelta minimum, base::TimeDelta maximum, size_t bucket_count, | 493 base::TimeDelta minimum, base::TimeDelta maximum, size_t bucket_count, |
| 476 Flags flags); | 494 Flags flags); |
| 477 | 495 |
| 478 protected: | 496 protected: |
| 479 LinearHistogram(const std::string& name, Sample minimum, | 497 LinearHistogram(const std::string& name, Sample minimum, |
| 480 Sample maximum, size_t bucket_count); | 498 Sample maximum, size_t bucket_count); |
| 481 | 499 |
| 482 LinearHistogram(const std::string& name, base::TimeDelta minimum, | 500 LinearHistogram(const std::string& name, base::TimeDelta minimum, |
| 483 base::TimeDelta maximum, size_t bucket_count); | 501 base::TimeDelta maximum, size_t bucket_count); |
| 484 | 502 |
| 485 virtual ~LinearHistogram() {} | |
| 486 | |
| 487 // Initialize ranges_ mapping. | 503 // Initialize ranges_ mapping. |
| 488 virtual void InitializeBucketRange(); | 504 virtual void InitializeBucketRange(); |
| 489 virtual double GetBucketSize(Count current, size_t i) const; | 505 virtual double GetBucketSize(Count current, size_t i) const; |
| 490 | 506 |
| 491 // If we have a description for a bucket, then return that. Otherwise | 507 // If we have a description for a bucket, then return that. Otherwise |
| 492 // let parent class provide a (numeric) description. | 508 // let parent class provide a (numeric) description. |
| 493 virtual const std::string GetAsciiBucketRange(size_t i) const; | 509 virtual const std::string GetAsciiBucketRange(size_t i) const; |
| 494 | 510 |
| 495 // Skip printing of name for numeric range if we have a name (and if this is | 511 // Skip printing of name for numeric range if we have a name (and if this is |
| 496 // an empty bucket). | 512 // an empty bucket). |
| (...skipping 23 matching lines...) Expand all Loading... |
| 520 | 536 |
| 521 private: | 537 private: |
| 522 explicit BooleanHistogram(const std::string& name) | 538 explicit BooleanHistogram(const std::string& name) |
| 523 : LinearHistogram(name, 1, 2, 3) { | 539 : LinearHistogram(name, 1, 2, 3) { |
| 524 } | 540 } |
| 525 | 541 |
| 526 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); | 542 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); |
| 527 }; | 543 }; |
| 528 | 544 |
| 529 //------------------------------------------------------------------------------ | 545 //------------------------------------------------------------------------------ |
| 546 |
| 547 // CustomHistogram is a histogram for a set of custom integers. |
| 548 class CustomHistogram : public Histogram { |
| 549 public: |
| 550 virtual ClassType histogram_type() const { return CUSTOM_HISTOGRAM; } |
| 551 |
| 552 static scoped_refptr<Histogram> FactoryGet(const std::string& name, |
| 553 const std::vector<int>& custom_ranges, Flags flags); |
| 554 |
| 555 protected: |
| 556 CustomHistogram(const std::string& name, |
| 557 const std::vector<int>& custom_ranges); |
| 558 |
| 559 // Initialize ranges_ mapping. |
| 560 virtual void InitializeBucketRange(); |
| 561 virtual double GetBucketSize(Count current, size_t i) const; |
| 562 |
| 563 private: |
| 564 // Temporary pointer used during construction/initialization, and then NULLed. |
| 565 const std::vector<int>* ranges_vector_; |
| 566 |
| 567 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
| 568 }; |
| 569 |
| 570 //------------------------------------------------------------------------------ |
| 530 // StatisticsRecorder handles all histograms in the system. It provides a | 571 // StatisticsRecorder handles all histograms in the system. It provides a |
| 531 // general place for histograms to register, and supports a global API for | 572 // general place for histograms to register, and supports a global API for |
| 532 // accessing (i.e., dumping, or graphing) the data in all the histograms. | 573 // accessing (i.e., dumping, or graphing) the data in all the histograms. |
| 533 | 574 |
| 534 class StatisticsRecorder { | 575 class StatisticsRecorder { |
| 535 public: | 576 public: |
| 536 typedef std::vector<scoped_refptr<Histogram> > Histograms; | 577 typedef std::vector<scoped_refptr<Histogram> > Histograms; |
| 537 | 578 |
| 538 StatisticsRecorder(); | 579 StatisticsRecorder(); |
| 539 | 580 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 // lock protects access to the above map. | 620 // lock protects access to the above map. |
| 580 static Lock* lock_; | 621 static Lock* lock_; |
| 581 | 622 |
| 582 // Dump all known histograms to log. | 623 // Dump all known histograms to log. |
| 583 static bool dump_on_exit_; | 624 static bool dump_on_exit_; |
| 584 | 625 |
| 585 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 626 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
| 586 }; | 627 }; |
| 587 | 628 |
| 588 #endif // BASE_HISTOGRAM_H_ | 629 #endif // BASE_HISTOGRAM_H_ |
| OLD | NEW |