Chromium Code Reviews| 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 } | 264 } |
| 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 int ClampValue(int value) { | |
|
Alexei Svitkine (slow)
2015/08/03 18:15:42
Put this in the anon namespace at the top of the f
amohammadkhan
2015/08/04 18:22:51
Done.
| |
| 275 if (value > Histogram::kSampleType_MAX - 1) | |
| 276 return Histogram::kSampleType_MAX - 1; | |
| 277 if (value < 0) | |
| 278 return 0; | |
| 279 return value; | |
| 280 } | |
| 281 | |
| 274 void Histogram::Add(int value) { | 282 void Histogram::Add(int value) { |
| 283 AddCount(value, 1); | |
| 284 } | |
| 285 | |
| 286 void Histogram::AddCount(int value, int count) { | |
| 275 DCHECK_EQ(0, ranges(0)); | 287 DCHECK_EQ(0, ranges(0)); |
| 276 DCHECK_EQ(kSampleType_MAX, ranges(bucket_count())); | 288 DCHECK_EQ(kSampleType_MAX, ranges(bucket_count())); |
| 289 if (count < 0) { | |
|
Alexei Svitkine (slow)
2015/08/03 18:15:42
If the body is a single line, no need for {}'s.
amohammadkhan
2015/08/04 18:22:51
Done.
| |
| 290 count = 0; | |
|
Alexei Svitkine (slow)
2015/08/03 18:15:42
Seems like a count of 0 would actually not change
amohammadkhan
2015/08/04 18:22:51
Done.
| |
| 291 } | |
| 292 int clamped_value = ClampValue(value); | |
| 293 samples_->Accumulate(clamped_value, count); | |
| 277 | 294 |
| 278 if (value > kSampleType_MAX - 1) | 295 FindAndRunCallback(clamped_value); |
| 279 value = kSampleType_MAX - 1; | |
| 280 if (value < 0) | |
| 281 value = 0; | |
| 282 samples_->Accumulate(value, 1); | |
| 283 | |
| 284 FindAndRunCallback(value); | |
| 285 } | 296 } |
| 286 | 297 |
| 287 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { | 298 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { |
| 288 return SnapshotSampleVector().Pass(); | 299 return SnapshotSampleVector().Pass(); |
| 289 } | 300 } |
| 290 | 301 |
| 291 void Histogram::AddSamples(const HistogramSamples& samples) { | 302 void Histogram::AddSamples(const HistogramSamples& samples) { |
| 292 samples_->Add(samples); | 303 samples_->Add(samples); |
| 293 } | 304 } |
| 294 | 305 |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 | 895 |
| 885 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 896 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
| 886 for (size_t i = 0; i < ranges.size(); i++) { | 897 for (size_t i = 0; i < ranges.size(); i++) { |
| 887 bucket_ranges->set_range(i, ranges[i]); | 898 bucket_ranges->set_range(i, ranges[i]); |
| 888 } | 899 } |
| 889 bucket_ranges->ResetChecksum(); | 900 bucket_ranges->ResetChecksum(); |
| 890 return bucket_ranges; | 901 return bucket_ranges; |
| 891 } | 902 } |
| 892 | 903 |
| 893 } // namespace base | 904 } // namespace base |
| OLD | NEW |