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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 127 } |
128 DCHECK_EQ(count, redundant_count_); | 128 DCHECK_EQ(count, redundant_count_); |
129 return count == redundant_count_; | 129 return count == redundant_count_; |
130 } | 130 } |
131 | 131 |
132 Histogram* Histogram::FactoryGet(const string& name, | 132 Histogram* Histogram::FactoryGet(const string& name, |
133 Sample minimum, | 133 Sample minimum, |
134 Sample maximum, | 134 Sample maximum, |
135 size_t bucket_count, | 135 size_t bucket_count, |
136 Flags flags) { | 136 Flags flags) { |
137 CHECK(InspectConstructionArguments(name, &minimum, &maximum, &bucket_count)); | 137 bool valid_arguments = |
| 138 InspectConstructionArguments(name, &minimum, &maximum, &bucket_count); |
| 139 DCHECK(valid_arguments); |
138 | 140 |
139 Histogram* histogram = StatisticsRecorder::FindHistogram(name); | 141 Histogram* histogram = StatisticsRecorder::FindHistogram(name); |
140 if (!histogram) { | 142 if (!histogram) { |
141 // To avoid racy destruction at shutdown, the following will be leaked. | 143 // To avoid racy destruction at shutdown, the following will be leaked. |
142 BucketRanges* ranges = new BucketRanges(bucket_count + 1); | 144 BucketRanges* ranges = new BucketRanges(bucket_count + 1); |
143 InitializeBucketRanges(minimum, maximum, bucket_count, ranges); | 145 InitializeBucketRanges(minimum, maximum, bucket_count, ranges); |
144 const BucketRanges* registered_ranges = | 146 const BucketRanges* registered_ranges = |
145 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); | 147 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); |
146 | 148 |
147 Histogram* tentative_histogram = | 149 Histogram* tentative_histogram = |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 size_t* bucket_count) { | 460 size_t* bucket_count) { |
459 // Defensive code for backward compatibility. | 461 // Defensive code for backward compatibility. |
460 if (*minimum < 1) { | 462 if (*minimum < 1) { |
461 DVLOG(1) << "Histogram: " << name << " has bad minimum: " << *minimum; | 463 DVLOG(1) << "Histogram: " << name << " has bad minimum: " << *minimum; |
462 *minimum = 1; | 464 *minimum = 1; |
463 } | 465 } |
464 if (*maximum >= kSampleType_MAX) { | 466 if (*maximum >= kSampleType_MAX) { |
465 DVLOG(1) << "Histogram: " << name << " has bad maximum: " << *maximum; | 467 DVLOG(1) << "Histogram: " << name << " has bad maximum: " << *maximum; |
466 *maximum = kSampleType_MAX - 1; | 468 *maximum = kSampleType_MAX - 1; |
467 } | 469 } |
| 470 if (*bucket_count >= kBucketCount_MAX) { |
| 471 DVLOG(1) << "Histogram: " << name << " has bad bucket_count: " |
| 472 << *bucket_count; |
| 473 *bucket_count = kBucketCount_MAX - 1; |
| 474 } |
468 | 475 |
469 if (*bucket_count < 3 || *bucket_count >= kBucketCount_MAX) | 476 if (*minimum >= *maximum) |
| 477 return false; |
| 478 if (*bucket_count < 3) |
470 return false; | 479 return false; |
471 if (*bucket_count > static_cast<size_t>(*maximum - *minimum + 2)) | 480 if (*bucket_count > static_cast<size_t>(*maximum - *minimum + 2)) |
472 return false; | 481 return false; |
473 return true; | 482 return true; |
474 } | 483 } |
475 | 484 |
476 bool Histogram::SerializeRanges(Pickle* pickle) const { | 485 bool Histogram::SerializeRanges(Pickle* pickle) const { |
477 return true; | 486 return true; |
478 } | 487 } |
479 | 488 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 // buckets. | 679 // buckets. |
671 //------------------------------------------------------------------------------ | 680 //------------------------------------------------------------------------------ |
672 | 681 |
673 LinearHistogram::~LinearHistogram() {} | 682 LinearHistogram::~LinearHistogram() {} |
674 | 683 |
675 Histogram* LinearHistogram::FactoryGet(const string& name, | 684 Histogram* LinearHistogram::FactoryGet(const string& name, |
676 Sample minimum, | 685 Sample minimum, |
677 Sample maximum, | 686 Sample maximum, |
678 size_t bucket_count, | 687 size_t bucket_count, |
679 Flags flags) { | 688 Flags flags) { |
680 CHECK(Histogram::InspectConstructionArguments(name, &minimum, &maximum, | 689 bool valid_arguments = Histogram::InspectConstructionArguments( |
681 &bucket_count)); | 690 name, &minimum, &maximum, &bucket_count); |
| 691 DCHECK(valid_arguments); |
682 | 692 |
683 Histogram* histogram = StatisticsRecorder::FindHistogram(name); | 693 Histogram* histogram = StatisticsRecorder::FindHistogram(name); |
684 if (!histogram) { | 694 if (!histogram) { |
685 // To avoid racy destruction at shutdown, the following will be leaked. | 695 // To avoid racy destruction at shutdown, the following will be leaked. |
686 BucketRanges* ranges = new BucketRanges(bucket_count + 1); | 696 BucketRanges* ranges = new BucketRanges(bucket_count + 1); |
687 InitializeBucketRanges(minimum, maximum, bucket_count, ranges); | 697 InitializeBucketRanges(minimum, maximum, bucket_count, ranges); |
688 const BucketRanges* registered_ranges = | 698 const BucketRanges* registered_ranges = |
689 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); | 699 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); |
690 | 700 |
691 LinearHistogram* tentative_histogram = | 701 LinearHistogram* tentative_histogram = |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 | 916 |
907 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 917 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
908 for (size_t i = 0; i < ranges.size(); i++) { | 918 for (size_t i = 0; i < ranges.size(); i++) { |
909 bucket_ranges->set_range(i, ranges[i]); | 919 bucket_ranges->set_range(i, ranges[i]); |
910 } | 920 } |
911 bucket_ranges->ResetChecksum(); | 921 bucket_ranges->ResetChecksum(); |
912 return bucket_ranges; | 922 return bucket_ranges; |
913 } | 923 } |
914 | 924 |
915 } // namespace base | 925 } // namespace base |
OLD | NEW |