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