| 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 #include "base/metrics/sparse_histogram.h" | 5 #include "base/metrics/sparse_histogram.h" |
| 6 | 6 |
| 7 #include "base/metrics/sample_map.h" | 7 #include "base/metrics/sample_map.h" |
| 8 #include "base/metrics/statistics_recorder.h" | 8 #include "base/metrics/statistics_recorder.h" |
| 9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 bool SparseHistogram::HasConstructionArguments( | 40 bool SparseHistogram::HasConstructionArguments( |
| 41 Sample expected_minimum, | 41 Sample expected_minimum, |
| 42 Sample expected_maximum, | 42 Sample expected_maximum, |
| 43 size_t expected_bucket_count) const { | 43 size_t expected_bucket_count) const { |
| 44 // SparseHistogram never has min/max/bucket_count limit. | 44 // SparseHistogram never has min/max/bucket_count limit. |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void SparseHistogram::Add(Sample value) { | 48 void SparseHistogram::Add(Sample value) { |
| 49 AddCount(value, 1); |
| 50 } |
| 51 |
| 52 void SparseHistogram::AddCount(Sample value, int count) { |
| 53 if (count <= 0) { |
| 54 NOTREACHED(); |
| 55 return; |
| 56 } |
| 49 { | 57 { |
| 50 base::AutoLock auto_lock(lock_); | 58 base::AutoLock auto_lock(lock_); |
| 51 samples_.Accumulate(value, 1); | 59 samples_.Accumulate(value, count); |
| 52 } | 60 } |
| 53 | 61 |
| 54 FindAndRunCallback(value); | 62 FindAndRunCallback(value); |
| 55 } | 63 } |
| 56 | 64 |
| 57 scoped_ptr<HistogramSamples> SparseHistogram::SnapshotSamples() const { | 65 scoped_ptr<HistogramSamples> SparseHistogram::SnapshotSamples() const { |
| 58 scoped_ptr<SampleMap> snapshot(new SampleMap()); | 66 scoped_ptr<SampleMap> snapshot(new SampleMap()); |
| 59 | 67 |
| 60 base::AutoLock auto_lock(lock_); | 68 base::AutoLock auto_lock(lock_); |
| 61 snapshot->Add(samples_); | 69 snapshot->Add(samples_); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 std::string* output) const { | 178 std::string* output) const { |
| 171 StringAppendF(output, | 179 StringAppendF(output, |
| 172 "Histogram: %s recorded %d samples", | 180 "Histogram: %s recorded %d samples", |
| 173 histogram_name().c_str(), | 181 histogram_name().c_str(), |
| 174 total_count); | 182 total_count); |
| 175 if (flags() & ~kHexRangePrintingFlag) | 183 if (flags() & ~kHexRangePrintingFlag) |
| 176 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); | 184 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); |
| 177 } | 185 } |
| 178 | 186 |
| 179 } // namespace base | 187 } // namespace base |
| OLD | NEW |