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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 static base::Histogram* counter(NULL); \ | 101 static base::Histogram* counter(NULL); \ |
102 if (!counter) \ | 102 if (!counter) \ |
103 counter = base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ | 103 counter = base::Histogram::FactoryTimeGet(name, min, max, bucket_count, \ |
104 base::Histogram::kNoFlags); \ | 104 base::Histogram::kNoFlags); \ |
105 DCHECK_EQ(name, counter->histogram_name()); \ | 105 DCHECK_EQ(name, counter->histogram_name()); \ |
106 if ((sample) < (max)) counter->AddTime(sample); \ | 106 if ((sample) < (max)) counter->AddTime(sample); \ |
107 } while (0) | 107 } while (0) |
108 | 108 |
109 // Support histograming of an enumerated value. The samples should always be | 109 // Support histograming of an enumerated value. The samples should always be |
110 // less than boundary_value. | 110 // less than boundary_value. |
111 | |
112 #define HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ | 111 #define HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ |
113 static base::Histogram* counter(NULL); \ | 112 static base::Histogram* counter(NULL); \ |
114 if (!counter) \ | 113 if (!counter) \ |
115 counter = base::LinearHistogram::FactoryGet(name, 1, boundary_value, \ | 114 counter = base::LinearHistogram::FactoryGet(name, 1, boundary_value, \ |
116 boundary_value + 1, base::Histogram::kNoFlags); \ | 115 boundary_value + 1, base::Histogram::kNoFlags); \ |
117 DCHECK_EQ(name, counter->histogram_name()); \ | 116 DCHECK_EQ(name, counter->histogram_name()); \ |
118 counter->Add(sample); \ | 117 counter->Add(sample); \ |
119 } while (0) | 118 } while (0) |
120 | 119 |
| 120 // Support histograming of an enumerated value. Samples should be one of the |
| 121 // std::vector<int> list provided via |custom_ranges|. You can use the helper |
| 122 // function |base::CustomHistogram::ArrayToCustomRanges(samples, num_samples)| |
| 123 // to transform a C-style array of valid sample values to a std::vector<int>. |
121 #define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ | 124 #define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ |
122 static base::Histogram* counter(NULL); \ | 125 static base::Histogram* counter(NULL); \ |
123 if (!counter) \ | 126 if (!counter) \ |
124 counter = base::CustomHistogram::FactoryGet(name, custom_ranges, \ | 127 counter = base::CustomHistogram::FactoryGet(name, custom_ranges, \ |
125 base::Histogram::kNoFlags); \ | 128 base::Histogram::kNoFlags); \ |
126 DCHECK_EQ(name, counter->histogram_name()); \ | 129 DCHECK_EQ(name, counter->histogram_name()); \ |
127 counter->Add(sample); \ | 130 counter->Add(sample); \ |
128 } while (0) | 131 } while (0) |
129 | 132 |
130 | 133 |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 class BASE_API CustomHistogram : public Histogram { | 660 class BASE_API CustomHistogram : public Histogram { |
658 public: | 661 public: |
659 | 662 |
660 static Histogram* FactoryGet(const std::string& name, | 663 static Histogram* FactoryGet(const std::string& name, |
661 const std::vector<Sample>& custom_ranges, | 664 const std::vector<Sample>& custom_ranges, |
662 Flags flags); | 665 Flags flags); |
663 | 666 |
664 // Overridden from Histogram: | 667 // Overridden from Histogram: |
665 virtual ClassType histogram_type() const; | 668 virtual ClassType histogram_type() const; |
666 | 669 |
| 670 // Helper method for transforming an array of valid enumeration values |
| 671 // to the std::vector<int> expected by HISTOGRAM_CUSTOM_ENUMERATION. |
| 672 // This function ensures that a guard bucket exists right after any |
| 673 // valid sample value (unless the next higher sample is also a valid value), |
| 674 // so that invalid samples never fall into the same bucket as valid samples. |
| 675 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, |
| 676 size_t num_values); |
| 677 |
667 protected: | 678 protected: |
668 CustomHistogram(const std::string& name, | 679 CustomHistogram(const std::string& name, |
669 const std::vector<Sample>& custom_ranges); | 680 const std::vector<Sample>& custom_ranges); |
670 | 681 |
671 // Initialize ranges_ mapping. | 682 // Initialize ranges_ mapping. |
672 void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges); | 683 void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges); |
673 virtual double GetBucketSize(Count current, size_t i) const; | 684 virtual double GetBucketSize(Count current, size_t i) const; |
674 | 685 |
675 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 686 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
676 }; | 687 }; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 | 744 |
734 // Dump all known histograms to log. | 745 // Dump all known histograms to log. |
735 static bool dump_on_exit_; | 746 static bool dump_on_exit_; |
736 | 747 |
737 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 748 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
738 }; | 749 }; |
739 | 750 |
740 } // namespace base | 751 } // namespace base |
741 | 752 |
742 #endif // BASE_METRICS_HISTOGRAM_H_ | 753 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |