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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 return ranges; | 120 return ranges; |
121 } | 121 } |
122 | 122 |
123 // Allocate the correct Histogram object off the heap (in case persistent | 123 // Allocate the correct Histogram object off the heap (in case persistent |
124 // memory is not available). | 124 // memory is not available). |
125 virtual HistogramBase* HeapAlloc(const BucketRanges* ranges) { | 125 virtual HistogramBase* HeapAlloc(const BucketRanges* ranges) { |
126 return new Histogram(name_, minimum_, maximum_, ranges); | 126 return new Histogram(name_, minimum_, maximum_, ranges); |
127 } | 127 } |
128 | 128 |
129 // Perform any required datafill on the just-created histogram. If | 129 // Perform any required datafill on the just-created histogram. If |
130 // overridden, be sure to call the "super" version. | 130 // overridden, be sure to call the "super" version. |
Alexei Svitkine (slow)
2016/03/14 18:48:59
Nit: Remove second sentence, since super version i
bcwhite
2016/03/15 00:00:21
It is, but there is no guarantee it will always re
| |
131 virtual void FillHistogram(HistogramBase* histogram) { | 131 virtual void FillHistogram(HistogramBase* histogram) {} |
132 histogram->SetFlags(flags_); | |
133 } | |
134 | 132 |
135 // These values are protected (instead of private) because they need to | 133 // These values are protected (instead of private) because they need to |
136 // be accessible to methods of sub-classes in order to avoid passing | 134 // be accessible to methods of sub-classes in order to avoid passing |
137 // unnecessary parameters everywhere. | 135 // unnecessary parameters everywhere. |
138 const std::string& name_; | 136 const std::string& name_; |
139 const HistogramType histogram_type_; | 137 const HistogramType histogram_type_; |
140 HistogramBase::Sample minimum_; | 138 HistogramBase::Sample minimum_; |
141 HistogramBase::Sample maximum_; | 139 HistogramBase::Sample maximum_; |
142 uint32_t bucket_count_; | 140 uint32_t bucket_count_; |
143 int32_t flags_; | 141 int32_t flags_; |
(...skipping 21 matching lines...) Expand all Loading... | |
165 // cases (such as with a CustomHistogram), they are calculated dynamically | 163 // cases (such as with a CustomHistogram), they are calculated dynamically |
166 // at run-time. In the latter case, those ctor parameters are zero and | 164 // at run-time. In the latter case, those ctor parameters are zero and |
167 // the results extracted from the result of CreateRanges(). | 165 // the results extracted from the result of CreateRanges(). |
168 if (bucket_count_ == 0) { | 166 if (bucket_count_ == 0) { |
169 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count()); | 167 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count()); |
170 minimum_ = registered_ranges->range(1); | 168 minimum_ = registered_ranges->range(1); |
171 maximum_ = registered_ranges->range(bucket_count_ - 1); | 169 maximum_ = registered_ranges->range(bucket_count_ - 1); |
172 } | 170 } |
173 | 171 |
174 // Try to create the histogram using a "persistent" allocator. As of | 172 // Try to create the histogram using a "persistent" allocator. As of |
175 // 2015-01-14, the availability of such is controlled by a base::Feature | 173 // 2016-02-25, the availability of such is controlled by a base::Feature |
176 // that is off by default. If the allocator doesn't exist or if | 174 // that is off by default. If the allocator doesn't exist or if |
177 // allocating from it fails, code below will allocate the histogram from | 175 // allocating from it fails, code below will allocate the histogram from |
178 // the process heap. | 176 // the process heap. |
179 PersistentMemoryAllocator::Reference histogram_ref = 0; | 177 PersistentMemoryAllocator::Reference histogram_ref = 0; |
180 HistogramBase* tentative_histogram = nullptr; | 178 HistogramBase* tentative_histogram = nullptr; |
181 PersistentMemoryAllocator* allocator = | 179 PersistentMemoryAllocator* allocator = |
182 GetPersistentHistogramMemoryAllocator(); | 180 GetPersistentHistogramMemoryAllocator(); |
183 if (allocator) { | 181 if (allocator) { |
184 flags_ |= HistogramBase::kIsPersistent; | |
185 tentative_histogram = AllocatePersistentHistogram( | 182 tentative_histogram = AllocatePersistentHistogram( |
186 allocator, | 183 allocator, |
187 histogram_type_, | 184 histogram_type_, |
188 name_, | 185 name_, |
189 minimum_, | 186 minimum_, |
190 maximum_, | 187 maximum_, |
191 registered_ranges, | 188 registered_ranges, |
192 flags_, | 189 flags_, |
193 &histogram_ref); | 190 &histogram_ref); |
194 } | 191 } |
195 | 192 |
196 // Handle the case where no persistent allocator is present or the | 193 // Handle the case where no persistent allocator is present or the |
197 // persistent allocation fails (perhaps because it is full). | 194 // persistent allocation fails (perhaps because it is full). |
198 if (!tentative_histogram) { | 195 if (!tentative_histogram) { |
199 DCHECK(!histogram_ref); // Should never have been set. | 196 DCHECK(!histogram_ref); // Should never have been set. |
200 DCHECK(!allocator); // Shouldn't have failed. | 197 DCHECK(!allocator); // Shouldn't have failed. |
201 flags_ &= ~HistogramBase::kIsPersistent; | 198 flags_ &= ~HistogramBase::kIsPersistent; |
202 tentative_histogram = HeapAlloc(registered_ranges); | 199 tentative_histogram = HeapAlloc(registered_ranges); |
200 tentative_histogram->SetFlags(flags_); | |
Alexei Svitkine (slow)
2016/03/14 18:49:00
Nit: Put this inside HeapAlloc()
bcwhite
2016/03/15 00:00:21
It would have to be done inside every HeapAlloc an
Alexei Svitkine (slow)
2016/03/16 15:25:43
To me, it seem a small implementation detail that
bcwhite
2016/03/16 15:42:48
I was thinking the same: It would be best as a cto
| |
203 } | 201 } |
204 | 202 |
205 FillHistogram(tentative_histogram); | 203 FillHistogram(tentative_histogram); |
206 histogram = | 204 histogram = |
207 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 205 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
208 | 206 |
209 // Persistent histograms need some follow-up processing. | 207 // Persistent histograms need some follow-up processing. |
210 if (histogram_ref) { | 208 if (histogram_ref) { |
211 FinalizePersistentHistogram(histogram_ref, | 209 FinalizePersistentHistogram(histogram_ref, |
212 histogram == tentative_histogram); | 210 histogram == tentative_histogram); |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 Sample sample = custom_ranges[i]; | 1153 Sample sample = custom_ranges[i]; |
1156 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) | 1154 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) |
1157 return false; | 1155 return false; |
1158 if (sample != 0) | 1156 if (sample != 0) |
1159 has_valid_range = true; | 1157 has_valid_range = true; |
1160 } | 1158 } |
1161 return has_valid_range; | 1159 return has_valid_range; |
1162 } | 1160 } |
1163 | 1161 |
1164 } // namespace base | 1162 } // namespace base |
OLD | NEW |