OLD | NEW |
1 // Copyright (c) 2011 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" |
11 | 11 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 size_t bucket_count, | 87 size_t bucket_count, |
88 Flags flags) { | 88 Flags flags) { |
89 Histogram* histogram(NULL); | 89 Histogram* histogram(NULL); |
90 | 90 |
91 // Defensive code. | 91 // Defensive code. |
92 if (minimum < 1) | 92 if (minimum < 1) |
93 minimum = 1; | 93 minimum = 1; |
94 if (maximum > kSampleType_MAX - 1) | 94 if (maximum > kSampleType_MAX - 1) |
95 maximum = kSampleType_MAX - 1; | 95 maximum = kSampleType_MAX - 1; |
96 | 96 |
| 97 DCHECK_GT(maximum, minimum); |
| 98 DCHECK_GT((Sample) bucket_count, 2); |
| 99 DCHECK_LE((Sample) bucket_count, maximum - minimum + 2); |
| 100 |
97 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { | 101 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { |
98 // Extra variable is not needed... but this keeps this section basically | 102 // Extra variable is not needed... but this keeps this section basically |
99 // identical to other derived classes in this file (and compiler will | 103 // identical to other derived classes in this file (and compiler will |
100 // optimize away the extra variable. | 104 // optimize away the extra variable. |
101 // To avoid racy destruction at shutdown, the following will be leaked. | 105 // To avoid racy destruction at shutdown, the following will be leaked. |
102 Histogram* tentative_histogram = | 106 Histogram* tentative_histogram = |
103 new Histogram(name, minimum, maximum, bucket_count); | 107 new Histogram(name, minimum, maximum, bucket_count); |
104 tentative_histogram->InitializeBucketRange(); | 108 tentative_histogram->InitializeBucketRange(); |
105 tentative_histogram->SetFlags(flags); | 109 tentative_histogram->SetFlags(flags); |
106 histogram = | 110 histogram = |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 Sample maximum, | 813 Sample maximum, |
810 size_t bucket_count, | 814 size_t bucket_count, |
811 Flags flags) { | 815 Flags flags) { |
812 Histogram* histogram(NULL); | 816 Histogram* histogram(NULL); |
813 | 817 |
814 if (minimum < 1) | 818 if (minimum < 1) |
815 minimum = 1; | 819 minimum = 1; |
816 if (maximum > kSampleType_MAX - 1) | 820 if (maximum > kSampleType_MAX - 1) |
817 maximum = kSampleType_MAX - 1; | 821 maximum = kSampleType_MAX - 1; |
818 | 822 |
| 823 DCHECK_GT(maximum, minimum); |
| 824 DCHECK_GT((Sample) bucket_count, 2); |
| 825 DCHECK_LE((Sample) bucket_count, maximum - minimum + 2); |
| 826 |
819 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { | 827 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { |
820 // To avoid racy destruction at shutdown, the following will be leaked. | 828 // To avoid racy destruction at shutdown, the following will be leaked. |
821 LinearHistogram* tentative_histogram = | 829 LinearHistogram* tentative_histogram = |
822 new LinearHistogram(name, minimum, maximum, bucket_count); | 830 new LinearHistogram(name, minimum, maximum, bucket_count); |
823 tentative_histogram->InitializeBucketRange(); | 831 tentative_histogram->InitializeBucketRange(); |
824 tentative_histogram->SetFlags(flags); | 832 tentative_histogram->SetFlags(flags); |
825 histogram = | 833 histogram = |
826 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 834 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
827 } | 835 } |
828 | 836 |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 | 1324 |
1317 // static | 1325 // static |
1318 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 1326 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
1319 // static | 1327 // static |
1320 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 1328 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
1321 // static | 1329 // static |
1322 base::Lock* StatisticsRecorder::lock_ = NULL; | 1330 base::Lock* StatisticsRecorder::lock_ = NULL; |
1323 // static | 1331 // static |
1324 bool StatisticsRecorder::dump_on_exit_ = false; | 1332 bool StatisticsRecorder::dump_on_exit_ = false; |
1325 } // namespace base | 1333 } // namespace base |
OLD | NEW |