OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See header file for details and examples. | 8 // See header file for details and examples. |
9 | 9 |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 if (!iter->ReadInt(&i)) | 126 if (!iter->ReadInt(&i)) |
127 return false; | 127 return false; |
128 counts_.push_back(i); | 128 counts_.push_back(i); |
129 count += i; | 129 count += i; |
130 } | 130 } |
131 DCHECK_EQ(count, redundant_count_); | 131 DCHECK_EQ(count, redundant_count_); |
132 return count == redundant_count_; | 132 return count == redundant_count_; |
133 } | 133 } |
134 | 134 |
135 // TODO(rtenneti): delete this code after debugging. | 135 // TODO(rtenneti): delete this code after debugging. |
136 void CheckCorruption(const Histogram& histogram) { | 136 void CheckCorruption(const Histogram& histogram, bool new_histogram) { |
137 const std::string& histogram_name = histogram.histogram_name(); | 137 const std::string& histogram_name = histogram.histogram_name(); |
138 char histogram_name_buf[128]; | 138 char histogram_name_buf[128]; |
139 base::strlcpy(histogram_name_buf, | 139 base::strlcpy(histogram_name_buf, |
140 histogram_name.c_str(), | 140 histogram_name.c_str(), |
141 arraysize(histogram_name_buf)); | 141 arraysize(histogram_name_buf)); |
142 base::debug::Alias(histogram_name_buf); | 142 base::debug::Alias(histogram_name_buf); |
143 | 143 |
144 bool debug_new_histogram[1]; | |
145 debug_new_histogram[0] = new_histogram; | |
146 base::debug::Alias(debug_new_histogram); | |
147 | |
144 Sample previous_range = -1; // Bottom range is always 0. | 148 Sample previous_range = -1; // Bottom range is always 0. |
145 for (size_t index = 0; index < histogram.bucket_count(); ++index) { | 149 for (size_t index = 0; index < histogram.bucket_count(); ++index) { |
146 int new_range = histogram.ranges(index); | 150 int new_range = histogram.ranges(index); |
147 if (previous_range >= new_range) { | 151 CHECK(previous_range < new_range); |
jar (doing other things)
2012/08/16 01:51:16
nit: CHECK_LT
kaiwang
2012/08/16 01:52:52
Done.
| |
148 CHECK(false); // Crash for the bucket order corruption. | |
149 } | |
150 previous_range = new_range; | 152 previous_range = new_range; |
151 } | 153 } |
152 | 154 |
153 if (!histogram.bucket_ranges()->HasValidChecksum()) { | 155 CHECK(histogram.bucket_ranges()->HasValidChecksum()); |
154 CHECK(false); // Crash for the checksum corruption. | |
155 } | |
156 } | 156 } |
157 | 157 |
158 Histogram* Histogram::FactoryGet(const string& name, | 158 Histogram* Histogram::FactoryGet(const string& name, |
159 Sample minimum, | 159 Sample minimum, |
160 Sample maximum, | 160 Sample maximum, |
161 size_t bucket_count, | 161 size_t bucket_count, |
162 int32 flags) { | 162 int32 flags) { |
163 bool valid_arguments = | 163 bool valid_arguments = |
164 InspectConstructionArguments(name, &minimum, &maximum, &bucket_count); | 164 InspectConstructionArguments(name, &minimum, &maximum, &bucket_count); |
165 DCHECK(valid_arguments); | 165 DCHECK(valid_arguments); |
166 | 166 |
167 Histogram* histogram = StatisticsRecorder::FindHistogram(name); | 167 Histogram* histogram = StatisticsRecorder::FindHistogram(name); |
168 if (!histogram) { | 168 if (!histogram) { |
169 // To avoid racy destruction at shutdown, the following will be leaked. | 169 // To avoid racy destruction at shutdown, the following will be leaked. |
170 BucketRanges* ranges = new BucketRanges(bucket_count + 1); | 170 BucketRanges* ranges = new BucketRanges(bucket_count + 1); |
171 InitializeBucketRanges(minimum, maximum, bucket_count, ranges); | 171 InitializeBucketRanges(minimum, maximum, bucket_count, ranges); |
172 const BucketRanges* registered_ranges = | 172 const BucketRanges* registered_ranges = |
173 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); | 173 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); |
174 | 174 |
175 Histogram* tentative_histogram = | 175 Histogram* tentative_histogram = |
176 new Histogram(name, minimum, maximum, bucket_count, registered_ranges); | 176 new Histogram(name, minimum, maximum, bucket_count, registered_ranges); |
177 CheckCorruption(*tentative_histogram, true); | |
178 | |
177 tentative_histogram->SetFlags(flags); | 179 tentative_histogram->SetFlags(flags); |
178 histogram = | 180 histogram = |
179 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 181 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
180 } | 182 } |
181 // TODO(rtenneti): delete this code after debugging. | 183 // TODO(rtenneti): delete this code after debugging. |
182 CheckCorruption(*histogram); | 184 CheckCorruption(*histogram, false); |
183 | 185 |
184 CHECK_EQ(HISTOGRAM, histogram->histogram_type()); | 186 CHECK_EQ(HISTOGRAM, histogram->histogram_type()); |
185 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); | 187 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); |
186 return histogram; | 188 return histogram; |
187 } | 189 } |
188 | 190 |
189 Histogram* Histogram::FactoryTimeGet(const string& name, | 191 Histogram* Histogram::FactoryTimeGet(const string& name, |
190 TimeDelta minimum, | 192 TimeDelta minimum, |
191 TimeDelta maximum, | 193 TimeDelta maximum, |
192 size_t bucket_count, | 194 size_t bucket_count, |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 if (!histogram) { | 723 if (!histogram) { |
722 // To avoid racy destruction at shutdown, the following will be leaked. | 724 // To avoid racy destruction at shutdown, the following will be leaked. |
723 BucketRanges* ranges = new BucketRanges(bucket_count + 1); | 725 BucketRanges* ranges = new BucketRanges(bucket_count + 1); |
724 InitializeBucketRanges(minimum, maximum, bucket_count, ranges); | 726 InitializeBucketRanges(minimum, maximum, bucket_count, ranges); |
725 const BucketRanges* registered_ranges = | 727 const BucketRanges* registered_ranges = |
726 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); | 728 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); |
727 | 729 |
728 LinearHistogram* tentative_histogram = | 730 LinearHistogram* tentative_histogram = |
729 new LinearHistogram(name, minimum, maximum, bucket_count, | 731 new LinearHistogram(name, minimum, maximum, bucket_count, |
730 registered_ranges); | 732 registered_ranges); |
733 CheckCorruption(*tentative_histogram, true); | |
734 | |
731 tentative_histogram->SetFlags(flags); | 735 tentative_histogram->SetFlags(flags); |
732 histogram = | 736 histogram = |
733 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 737 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
734 } | 738 } |
735 // TODO(rtenneti): delete this code after debugging. | 739 // TODO(rtenneti): delete this code after debugging. |
736 CheckCorruption(*histogram); | 740 CheckCorruption(*histogram, false); |
737 | 741 |
738 CHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type()); | 742 CHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type()); |
739 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); | 743 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); |
740 return histogram; | 744 return histogram; |
741 } | 745 } |
742 | 746 |
743 Histogram* LinearHistogram::FactoryTimeGet(const string& name, | 747 Histogram* LinearHistogram::FactoryTimeGet(const string& name, |
744 TimeDelta minimum, | 748 TimeDelta minimum, |
745 TimeDelta maximum, | 749 TimeDelta maximum, |
746 size_t bucket_count, | 750 size_t bucket_count, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 Histogram* histogram = StatisticsRecorder::FindHistogram(name); | 818 Histogram* histogram = StatisticsRecorder::FindHistogram(name); |
815 if (!histogram) { | 819 if (!histogram) { |
816 // To avoid racy destruction at shutdown, the following will be leaked. | 820 // To avoid racy destruction at shutdown, the following will be leaked. |
817 BucketRanges* ranges = new BucketRanges(4); | 821 BucketRanges* ranges = new BucketRanges(4); |
818 LinearHistogram::InitializeBucketRanges(1, 2, 3, ranges); | 822 LinearHistogram::InitializeBucketRanges(1, 2, 3, ranges); |
819 const BucketRanges* registered_ranges = | 823 const BucketRanges* registered_ranges = |
820 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); | 824 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); |
821 | 825 |
822 BooleanHistogram* tentative_histogram = | 826 BooleanHistogram* tentative_histogram = |
823 new BooleanHistogram(name, registered_ranges); | 827 new BooleanHistogram(name, registered_ranges); |
828 CheckCorruption(*tentative_histogram, true); | |
829 | |
824 tentative_histogram->SetFlags(flags); | 830 tentative_histogram->SetFlags(flags); |
825 histogram = | 831 histogram = |
826 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 832 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
827 } | 833 } |
828 // TODO(rtenneti): delete this code after debugging. | 834 // TODO(rtenneti): delete this code after debugging. |
829 CheckCorruption(*histogram); | 835 CheckCorruption(*histogram, false); |
830 | 836 |
831 CHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type()); | 837 CHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type()); |
832 return histogram; | 838 return histogram; |
833 } | 839 } |
834 | 840 |
835 Histogram::ClassType BooleanHistogram::histogram_type() const { | 841 Histogram::ClassType BooleanHistogram::histogram_type() const { |
836 return BOOLEAN_HISTOGRAM; | 842 return BOOLEAN_HISTOGRAM; |
837 } | 843 } |
838 | 844 |
839 void BooleanHistogram::AddBoolean(bool value) { | 845 void BooleanHistogram::AddBoolean(bool value) { |
(...skipping 15 matching lines...) Expand all Loading... | |
855 | 861 |
856 Histogram* histogram = StatisticsRecorder::FindHistogram(name); | 862 Histogram* histogram = StatisticsRecorder::FindHistogram(name); |
857 if (!histogram) { | 863 if (!histogram) { |
858 BucketRanges* ranges = CreateBucketRangesFromCustomRanges(custom_ranges); | 864 BucketRanges* ranges = CreateBucketRangesFromCustomRanges(custom_ranges); |
859 const BucketRanges* registered_ranges = | 865 const BucketRanges* registered_ranges = |
860 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); | 866 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); |
861 | 867 |
862 // To avoid racy destruction at shutdown, the following will be leaked. | 868 // To avoid racy destruction at shutdown, the following will be leaked. |
863 CustomHistogram* tentative_histogram = | 869 CustomHistogram* tentative_histogram = |
864 new CustomHistogram(name, registered_ranges); | 870 new CustomHistogram(name, registered_ranges); |
871 CheckCorruption(*tentative_histogram, true); | |
872 | |
865 tentative_histogram->SetFlags(flags); | 873 tentative_histogram->SetFlags(flags); |
866 | 874 |
867 histogram = | 875 histogram = |
868 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 876 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
869 } | 877 } |
870 // TODO(rtenneti): delete this code after debugging. | 878 // TODO(rtenneti): delete this code after debugging. |
871 CheckCorruption(*histogram); | 879 CheckCorruption(*histogram, false); |
872 | 880 |
873 CHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM); | 881 CHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM); |
874 return histogram; | 882 return histogram; |
875 } | 883 } |
876 | 884 |
877 Histogram::ClassType CustomHistogram::histogram_type() const { | 885 Histogram::ClassType CustomHistogram::histogram_type() const { |
878 return CUSTOM_HISTOGRAM; | 886 return CUSTOM_HISTOGRAM; |
879 } | 887 } |
880 | 888 |
881 // static | 889 // static |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
949 | 957 |
950 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 958 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
951 for (size_t i = 0; i < ranges.size(); i++) { | 959 for (size_t i = 0; i < ranges.size(); i++) { |
952 bucket_ranges->set_range(i, ranges[i]); | 960 bucket_ranges->set_range(i, ranges[i]); |
953 } | 961 } |
954 bucket_ranges->ResetChecksum(); | 962 bucket_ranges->ResetChecksum(); |
955 return bucket_ranges; | 963 return bucket_ranges; |
956 } | 964 } |
957 | 965 |
958 } // namespace base | 966 } // namespace base |
OLD | NEW |