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 // 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 void* iter = NULL; | 262 void* iter = NULL; |
263 if (!pickle.ReadString(&iter, &histogram_name) || | 263 if (!pickle.ReadString(&iter, &histogram_name) || |
264 !pickle.ReadInt(&iter, &declared_min) || | 264 !pickle.ReadInt(&iter, &declared_min) || |
265 !pickle.ReadInt(&iter, &declared_max) || | 265 !pickle.ReadInt(&iter, &declared_max) || |
266 !pickle.ReadSize(&iter, &bucket_count) || | 266 !pickle.ReadSize(&iter, &bucket_count) || |
267 !pickle.ReadUInt32(&iter, &range_checksum) || | 267 !pickle.ReadUInt32(&iter, &range_checksum) || |
268 !pickle.ReadInt(&iter, &histogram_type) || | 268 !pickle.ReadInt(&iter, &histogram_type) || |
269 !pickle.ReadInt(&iter, &pickle_flags) || | 269 !pickle.ReadInt(&iter, &pickle_flags) || |
270 !sample.Histogram::SampleSet::Deserialize(&iter, pickle)) { | 270 !sample.Histogram::SampleSet::Deserialize(&iter, pickle)) { |
271 LOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; | 271 DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; |
272 return false; | 272 return false; |
273 } | 273 } |
274 DCHECK(pickle_flags & kIPCSerializationSourceFlag); | 274 DCHECK(pickle_flags & kIPCSerializationSourceFlag); |
275 // Since these fields may have come from an untrusted renderer, do additional | 275 // Since these fields may have come from an untrusted renderer, do additional |
276 // checks above and beyond those in Histogram::Initialize() | 276 // checks above and beyond those in Histogram::Initialize() |
277 if (declared_max <= 0 || declared_min <= 0 || declared_max < declared_min || | 277 if (declared_max <= 0 || declared_min <= 0 || declared_max < declared_min || |
278 INT_MAX / sizeof(Count) <= bucket_count || bucket_count < 2) { | 278 INT_MAX / sizeof(Count) <= bucket_count || bucket_count < 2) { |
279 LOG(ERROR) << "Values error decoding Histogram: " << histogram_name; | 279 DLOG(ERROR) << "Values error decoding Histogram: " << histogram_name; |
280 return false; | 280 return false; |
281 } | 281 } |
282 | 282 |
283 Flags flags = static_cast<Flags>(pickle_flags & ~kIPCSerializationSourceFlag); | 283 Flags flags = static_cast<Flags>(pickle_flags & ~kIPCSerializationSourceFlag); |
284 | 284 |
285 DCHECK_NE(NOT_VALID_IN_RENDERER, histogram_type); | 285 DCHECK_NE(NOT_VALID_IN_RENDERER, histogram_type); |
286 | 286 |
287 Histogram* render_histogram(NULL); | 287 Histogram* render_histogram(NULL); |
288 | 288 |
289 if (histogram_type == HISTOGRAM) { | 289 if (histogram_type == HISTOGRAM) { |
290 render_histogram = Histogram::FactoryGet( | 290 render_histogram = Histogram::FactoryGet( |
291 histogram_name, declared_min, declared_max, bucket_count, flags); | 291 histogram_name, declared_min, declared_max, bucket_count, flags); |
292 } else if (histogram_type == LINEAR_HISTOGRAM) { | 292 } else if (histogram_type == LINEAR_HISTOGRAM) { |
293 render_histogram = LinearHistogram::FactoryGet( | 293 render_histogram = LinearHistogram::FactoryGet( |
294 histogram_name, declared_min, declared_max, bucket_count, flags); | 294 histogram_name, declared_min, declared_max, bucket_count, flags); |
295 } else if (histogram_type == BOOLEAN_HISTOGRAM) { | 295 } else if (histogram_type == BOOLEAN_HISTOGRAM) { |
296 render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags); | 296 render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags); |
297 } else { | 297 } else { |
298 LOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: " | 298 DLOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: " |
299 << histogram_type; | 299 << histogram_type; |
300 return false; | 300 return false; |
301 } | 301 } |
302 | 302 |
303 DCHECK_EQ(render_histogram->declared_min(), declared_min); | 303 DCHECK_EQ(render_histogram->declared_min(), declared_min); |
304 DCHECK_EQ(render_histogram->declared_max(), declared_max); | 304 DCHECK_EQ(render_histogram->declared_max(), declared_max); |
305 DCHECK_EQ(render_histogram->bucket_count(), bucket_count); | 305 DCHECK_EQ(render_histogram->bucket_count(), bucket_count); |
306 DCHECK_EQ(render_histogram->range_checksum(), range_checksum); | 306 DCHECK_EQ(render_histogram->range_checksum(), range_checksum); |
307 DCHECK_EQ(render_histogram->histogram_type(), histogram_type); | 307 DCHECK_EQ(render_histogram->histogram_type(), histogram_type); |
308 | 308 |
309 if (render_histogram->flags() & kIPCSerializationSourceFlag) { | 309 if (render_histogram->flags() & kIPCSerializationSourceFlag) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 cached_ranges_(new CachedRanges(bucket_count + 1, 0)), | 426 cached_ranges_(new CachedRanges(bucket_count + 1, 0)), |
427 range_checksum_(0), | 427 range_checksum_(0), |
428 sample_() { | 428 sample_() { |
429 Initialize(); | 429 Initialize(); |
430 } | 430 } |
431 | 431 |
432 Histogram::~Histogram() { | 432 Histogram::~Histogram() { |
433 if (StatisticsRecorder::dump_on_exit()) { | 433 if (StatisticsRecorder::dump_on_exit()) { |
434 std::string output; | 434 std::string output; |
435 WriteAscii(true, "\n", &output); | 435 WriteAscii(true, "\n", &output); |
436 LOG(INFO) << output; | 436 DLOG(INFO) << output; |
437 } | 437 } |
438 | 438 |
439 // Just to make sure most derived class did this properly... | 439 // Just to make sure most derived class did this properly... |
440 DCHECK(ValidateBucketRanges()); | 440 DCHECK(ValidateBucketRanges()); |
441 } | 441 } |
442 | 442 |
443 // Calculate what range of values are held in each bucket. | 443 // Calculate what range of values are held in each bucket. |
444 // We have to be careful that we don't pick a ratio between starting points in | 444 // We have to be careful that we don't pick a ratio between starting points in |
445 // consecutive buckets that is sooo small, that the integer bounds are the same | 445 // consecutive buckets that is sooo small, that the integer bounds are the same |
446 // (effectively making one bucket get no values). We need to avoid: | 446 // (effectively making one bucket get no values). We need to avoid: |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 histograms_ = new HistogramMap; | 1018 histograms_ = new HistogramMap; |
1019 ranges_ = new RangesMap; | 1019 ranges_ = new RangesMap; |
1020 } | 1020 } |
1021 | 1021 |
1022 StatisticsRecorder::~StatisticsRecorder() { | 1022 StatisticsRecorder::~StatisticsRecorder() { |
1023 DCHECK(histograms_ && lock_); | 1023 DCHECK(histograms_ && lock_); |
1024 | 1024 |
1025 if (dump_on_exit_) { | 1025 if (dump_on_exit_) { |
1026 std::string output; | 1026 std::string output; |
1027 WriteGraph("", &output); | 1027 WriteGraph("", &output); |
1028 LOG(INFO) << output; | 1028 DLOG(INFO) << output; |
1029 } | 1029 } |
1030 // Clean up. | 1030 // Clean up. |
1031 HistogramMap* histograms = NULL; | 1031 HistogramMap* histograms = NULL; |
1032 { | 1032 { |
1033 base::AutoLock auto_lock(*lock_); | 1033 base::AutoLock auto_lock(*lock_); |
1034 histograms = histograms_; | 1034 histograms = histograms_; |
1035 histograms_ = NULL; | 1035 histograms_ = NULL; |
1036 } | 1036 } |
1037 RangesMap* ranges = NULL; | 1037 RangesMap* ranges = NULL; |
1038 { | 1038 { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 | 1282 |
1283 // static | 1283 // static |
1284 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 1284 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
1285 // static | 1285 // static |
1286 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 1286 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
1287 // static | 1287 // static |
1288 base::Lock* StatisticsRecorder::lock_ = NULL; | 1288 base::Lock* StatisticsRecorder::lock_ = NULL; |
1289 // static | 1289 // static |
1290 bool StatisticsRecorder::dump_on_exit_ = false; | 1290 bool StatisticsRecorder::dump_on_exit_ = false; |
1291 } // namespace base | 1291 } // namespace base |
OLD | NEW |