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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 }; | 147 }; |
148 | 148 |
149 HistogramBase* Histogram::Factory::Build() { | 149 HistogramBase* Histogram::Factory::Build() { |
150 // Import histograms from known persistent storage. Histograms could have | 150 // Import histograms from known persistent storage. Histograms could have |
151 // been added by other processes and they must be fetched and recognized | 151 // been added by other processes and they must be fetched and recognized |
152 // locally in order to be found by FindHistograms() below. If the persistent | 152 // locally in order to be found by FindHistograms() below. If the persistent |
153 // memory segment is not shared between processes, this call does nothing. | 153 // memory segment is not shared between processes, this call does nothing. |
154 ImportPersistentHistograms(); | 154 ImportPersistentHistograms(); |
155 | 155 |
156 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name_); | 156 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name_); |
157 | |
158 // crbug.com/588946 debugging. See comment at end of function. | |
159 const BucketRanges* created_ranges; | |
Alexei Svitkine (slow)
2016/02/26 19:12:50
Please initialize these to nullptr or something, e
bcwhite
2016/02/26 20:31:18
Done.
| |
160 const BucketRanges* registered_ranges; | |
161 PersistentMemoryAllocator::Reference histogram_ref; | |
162 HistogramBase* tentative_histogram; | |
163 PersistentMemoryAllocator* allocator; | |
164 | |
157 if (!histogram) { | 165 if (!histogram) { |
158 // To avoid racy destruction at shutdown, the following will be leaked. | 166 // To avoid racy destruction at shutdown, the following will be leaked. |
159 const BucketRanges* created_ranges = CreateRanges(); | 167 created_ranges = CreateRanges(); |
160 const BucketRanges* registered_ranges = | 168 registered_ranges = |
161 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(created_ranges); | 169 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(created_ranges); |
162 | 170 |
163 // In most cases, the bucket-count, minimum, and maximum values are known | 171 // In most cases, the bucket-count, minimum, and maximum values are known |
164 // when the code is written and so are passed in explicitly. In other | 172 // when the code is written and so are passed in explicitly. In other |
165 // cases (such as with a CustomHistogram), they are calculated dynamically | 173 // cases (such as with a CustomHistogram), they are calculated dynamically |
166 // at run-time. In the latter case, those ctor parameters are zero and | 174 // at run-time. In the latter case, those ctor parameters are zero and |
167 // the results extracted from the result of CreateRanges(). | 175 // the results extracted from the result of CreateRanges(). |
168 if (bucket_count_ == 0) { | 176 if (bucket_count_ == 0) { |
169 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count()); | 177 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count()); |
170 minimum_ = registered_ranges->range(1); | 178 minimum_ = registered_ranges->range(1); |
171 maximum_ = registered_ranges->range(bucket_count_ - 1); | 179 maximum_ = registered_ranges->range(bucket_count_ - 1); |
172 } | 180 } |
173 | 181 |
174 // Try to create the histogram using a "persistent" allocator. As of | 182 // 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 | 183 // 2015-01-14, the availability of such is controlled by a base::Feature |
176 // that is off by default. If the allocator doesn't exist or if | 184 // 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 | 185 // allocating from it fails, code below will allocate the histogram from |
178 // the process heap. | 186 // the process heap. |
179 PersistentMemoryAllocator::Reference histogram_ref = 0; | 187 histogram_ref = 0; |
180 HistogramBase* tentative_histogram = nullptr; | 188 tentative_histogram = nullptr; |
181 PersistentMemoryAllocator* allocator = | 189 allocator = |
182 GetPersistentHistogramMemoryAllocator(); | 190 GetPersistentHistogramMemoryAllocator(); |
183 if (allocator) { | 191 if (allocator) { |
184 flags_ |= HistogramBase::kIsPersistent; | 192 flags_ |= HistogramBase::kIsPersistent; |
185 tentative_histogram = AllocatePersistentHistogram( | 193 tentative_histogram = AllocatePersistentHistogram( |
186 allocator, | 194 allocator, |
187 histogram_type_, | 195 histogram_type_, |
188 name_, | 196 name_, |
189 minimum_, | 197 minimum_, |
190 maximum_, | 198 maximum_, |
191 registered_ranges, | 199 registered_ranges, |
(...skipping 24 matching lines...) Expand all Loading... | |
216 DCHECK_EQ(histogram_type_, histogram->GetHistogramType()); | 224 DCHECK_EQ(histogram_type_, histogram->GetHistogramType()); |
217 if (bucket_count_ != 0 && | 225 if (bucket_count_ != 0 && |
218 !histogram->HasConstructionArguments(minimum_, maximum_, bucket_count_)) { | 226 !histogram->HasConstructionArguments(minimum_, maximum_, bucket_count_)) { |
219 // The construction arguments do not match the existing histogram. This can | 227 // The construction arguments do not match the existing histogram. This can |
220 // come about if an extension updates in the middle of a chrome run and has | 228 // come about if an extension updates in the middle of a chrome run and has |
221 // changed one of them, or simply by bad code within Chrome itself. We | 229 // changed one of them, or simply by bad code within Chrome itself. We |
222 // return NULL here with the expectation that bad code in Chrome will crash | 230 // return NULL here with the expectation that bad code in Chrome will crash |
223 // on dereference, but extension/Pepper APIs will guard against NULL and not | 231 // on dereference, but extension/Pepper APIs will guard against NULL and not |
224 // crash. | 232 // crash. |
225 DLOG(ERROR) << "Histogram " << name_ << " has bad construction arguments"; | 233 DLOG(ERROR) << "Histogram " << name_ << " has bad construction arguments"; |
226 return nullptr; | 234 histogram = nullptr; |
227 } | 235 } |
236 | |
237 #if !DCHECK_IS_ON() // Don't affect tests, only release builds. | |
238 // For the moment, crash here so that collected crash reports have access | |
239 // to the construction values in order to figure out why this is failing. | |
240 // TODO(bcwhite): Remove this once crbug.com/588946 is resolved. Also remove | |
241 // from beta-branch because we don't want crashes due to misbehaving | |
242 // extensions (see comment above). | |
243 if (!histogram) { | |
244 HistogramType histogram_type = histogram_type_; | |
245 HistogramBase::Sample minimum = minimum_; | |
246 HistogramBase::Sample maximum = maximum_; | |
247 uint32_t bucket_count = bucket_count_; | |
248 int32_t flags = flags_; | |
249 CHECK(histogram); | |
250 base::debug::Alias(&histogram_type); | |
251 base::debug::Alias(&minimum); | |
252 base::debug::Alias(&maximum); | |
253 base::debug::Alias(&bucket_count); | |
254 base::debug::Alias(&flags); | |
255 base::debug::Alias(&created_ranges); | |
256 base::debug::Alias(®istered_ranges); | |
257 base::debug::Alias(&histogram_ref); | |
258 base::debug::Alias(&tentative_histogram); | |
259 base::debug::Alias(&allocator); | |
260 base::debug::Alias(&tentative_histogram); | |
261 } | |
262 #endif | |
263 | |
228 return histogram; | 264 return histogram; |
229 } | 265 } |
230 | 266 |
231 HistogramBase* Histogram::FactoryGet(const std::string& name, | 267 HistogramBase* Histogram::FactoryGet(const std::string& name, |
232 Sample minimum, | 268 Sample minimum, |
233 Sample maximum, | 269 Sample maximum, |
234 uint32_t bucket_count, | 270 uint32_t bucket_count, |
235 int32_t flags) { | 271 int32_t flags) { |
236 bool valid_arguments = | 272 bool valid_arguments = |
237 InspectConstructionArguments(name, &minimum, &maximum, &bucket_count); | 273 InspectConstructionArguments(name, &minimum, &maximum, &bucket_count); |
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 Sample sample = custom_ranges[i]; | 1191 Sample sample = custom_ranges[i]; |
1156 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) | 1192 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) |
1157 return false; | 1193 return false; |
1158 if (sample != 0) | 1194 if (sample != 0) |
1159 has_valid_range = true; | 1195 has_valid_range = true; |
1160 } | 1196 } |
1161 return has_valid_range; | 1197 return has_valid_range; |
1162 } | 1198 } |
1163 | 1199 |
1164 } // namespace base | 1200 } // namespace base |
OLD | NEW |