| 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 265 |
| 266 bool Histogram::HasConstructionArguments(Sample expected_minimum, | 266 bool Histogram::HasConstructionArguments(Sample expected_minimum, |
| 267 Sample expected_maximum, | 267 Sample expected_maximum, |
| 268 size_t expected_bucket_count) const { | 268 size_t expected_bucket_count) const { |
| 269 return ((expected_minimum == declared_min_) && | 269 return ((expected_minimum == declared_min_) && |
| 270 (expected_maximum == declared_max_) && | 270 (expected_maximum == declared_max_) && |
| 271 (expected_bucket_count == bucket_count())); | 271 (expected_bucket_count == bucket_count())); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void Histogram::Add(int value) { | 274 void Histogram::Add(int value) { |
| 275 AddCount(value, 1); |
| 276 } |
| 277 |
| 278 void Histogram::AddCount(int value, int count) { |
| 275 DCHECK_EQ(0, ranges(0)); | 279 DCHECK_EQ(0, ranges(0)); |
| 276 DCHECK_EQ(kSampleType_MAX, ranges(bucket_count())); | 280 DCHECK_EQ(kSampleType_MAX, ranges(bucket_count())); |
| 277 | 281 |
| 278 if (value > kSampleType_MAX - 1) | 282 if (value > kSampleType_MAX - 1) |
| 279 value = kSampleType_MAX - 1; | 283 value = kSampleType_MAX - 1; |
| 280 if (value < 0) | 284 if (value < 0) |
| 281 value = 0; | 285 value = 0; |
| 282 samples_->Accumulate(value, 1); | 286 if (count <= 0) { |
| 287 NOTREACHED(); |
| 288 return; |
| 289 } |
| 290 samples_->Accumulate(value, count); |
| 283 | 291 |
| 284 FindAndRunCallback(value); | 292 FindAndRunCallback(value); |
| 285 } | 293 } |
| 286 | 294 |
| 287 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { | 295 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { |
| 288 return SnapshotSampleVector().Pass(); | 296 return SnapshotSampleVector().Pass(); |
| 289 } | 297 } |
| 290 | 298 |
| 291 void Histogram::AddSamples(const HistogramSamples& samples) { | 299 void Histogram::AddSamples(const HistogramSamples& samples) { |
| 292 samples_->Add(samples); | 300 samples_->Add(samples); |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 | 892 |
| 885 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 893 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
| 886 for (size_t i = 0; i < ranges.size(); i++) { | 894 for (size_t i = 0; i < ranges.size(); i++) { |
| 887 bucket_ranges->set_range(i, ranges[i]); | 895 bucket_ranges->set_range(i, ranges[i]); |
| 888 } | 896 } |
| 889 bucket_ranges->ResetChecksum(); | 897 bucket_ranges->ResetChecksum(); |
| 890 return bucket_ranges; | 898 return bucket_ranges; |
| 891 } | 899 } |
| 892 | 900 |
| 893 } // namespace base | 901 } // namespace base |
| OLD | NEW |