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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 | 277 |
278 if (value > kSampleType_MAX - 1) | 278 if (value > kSampleType_MAX - 1) |
279 value = kSampleType_MAX - 1; | 279 value = kSampleType_MAX - 1; |
280 if (value < 0) | 280 if (value < 0) |
281 value = 0; | 281 value = 0; |
282 samples_->Accumulate(value, 1); | 282 samples_->Accumulate(value, 1); |
283 | 283 |
284 FindAndRunCallback(value); | 284 FindAndRunCallback(value); |
285 } | 285 } |
286 | 286 |
287 void Histogram::MultiAdd(int value, int count) { | |
Alexei Svitkine (slow)
2015/07/31 15:39:27
We should disallow negative values.
amohammadkhan
2015/08/03 17:30:43
Done. I change negative values to zero. Is it good
| |
288 DCHECK_EQ(0, ranges(0)); | |
289 DCHECK_EQ(kSampleType_MAX, ranges(bucket_count())); | |
290 | |
291 if (value > kSampleType_MAX - 1) | |
292 value = kSampleType_MAX - 1; | |
293 if (value < 0) | |
294 value = 0; | |
Alexei Svitkine (slow)
2015/07/31 15:39:27
Can you make a helper function for this clamping i
amohammadkhan
2015/08/03 17:30:43
Done.
| |
295 samples_->Accumulate(value, count); | |
296 | |
297 FindAndRunCallback(value); | |
298 | |
Alexei Svitkine (slow)
2015/07/31 15:39:27
Nit: Remove empty line.
amohammadkhan
2015/08/03 17:30:43
Done.
| |
299 } | |
300 | |
287 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { | 301 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { |
288 return SnapshotSampleVector().Pass(); | 302 return SnapshotSampleVector().Pass(); |
289 } | 303 } |
290 | 304 |
291 void Histogram::AddSamples(const HistogramSamples& samples) { | 305 void Histogram::AddSamples(const HistogramSamples& samples) { |
292 samples_->Add(samples); | 306 samples_->Add(samples); |
293 } | 307 } |
294 | 308 |
295 bool Histogram::AddSamplesFromPickle(PickleIterator* iter) { | 309 bool Histogram::AddSamplesFromPickle(PickleIterator* iter) { |
296 return samples_->AddFromPickle(iter); | 310 return samples_->AddFromPickle(iter); |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
884 | 898 |
885 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 899 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
886 for (size_t i = 0; i < ranges.size(); i++) { | 900 for (size_t i = 0; i < ranges.size(); i++) { |
887 bucket_ranges->set_range(i, ranges[i]); | 901 bucket_ranges->set_range(i, ranges[i]); |
888 } | 902 } |
889 bucket_ranges->ResetChecksum(); | 903 bucket_ranges->ResetChecksum(); |
890 return bucket_ranges; | 904 return bucket_ranges; |
891 } | 905 } |
892 | 906 |
893 } // namespace base | 907 } // namespace base |
OLD | NEW |