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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/metrics/metrics_hashes.h" | 10 #include "base/metrics/metrics_hashes.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash())); | 129 std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash())); |
130 base::AutoLock auto_lock(lock_); | 130 base::AutoLock auto_lock(lock_); |
131 snapshot->Add(*samples_); | 131 snapshot->Add(*samples_); |
132 | 132 |
133 // Subtract what was previously logged and update that information. | 133 // Subtract what was previously logged and update that information. |
134 snapshot->Subtract(*logged_samples_); | 134 snapshot->Subtract(*logged_samples_); |
135 logged_samples_->Add(*snapshot); | 135 logged_samples_->Add(*snapshot); |
136 return std::move(snapshot); | 136 return std::move(snapshot); |
137 } | 137 } |
138 | 138 |
| 139 std::unique_ptr<HistogramSamples> SparseHistogram::SnapshotDifference() const { |
| 140 std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash())); |
| 141 base::AutoLock auto_lock(lock_); |
| 142 snapshot->Add(*samples_); |
| 143 |
| 144 // Subtract what was previously logged and then return. |
| 145 snapshot->Subtract(*logged_samples_); |
| 146 return std::move(snapshot); |
| 147 } |
| 148 |
139 void SparseHistogram::AddSamples(const HistogramSamples& samples) { | 149 void SparseHistogram::AddSamples(const HistogramSamples& samples) { |
140 base::AutoLock auto_lock(lock_); | 150 base::AutoLock auto_lock(lock_); |
141 samples_->Add(samples); | 151 samples_->Add(samples); |
142 } | 152 } |
143 | 153 |
144 bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) { | 154 bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) { |
145 base::AutoLock auto_lock(lock_); | 155 base::AutoLock auto_lock(lock_); |
146 return samples_->AddFromPickle(iter); | 156 return samples_->AddFromPickle(iter); |
147 } | 157 } |
148 | 158 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 std::string* output) const { | 276 std::string* output) const { |
267 StringAppendF(output, | 277 StringAppendF(output, |
268 "Histogram: %s recorded %d samples", | 278 "Histogram: %s recorded %d samples", |
269 histogram_name().c_str(), | 279 histogram_name().c_str(), |
270 total_count); | 280 total_count); |
271 if (flags() & ~kHexRangePrintingFlag) | 281 if (flags() & ~kHexRangePrintingFlag) |
272 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); | 282 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); |
273 } | 283 } |
274 | 284 |
275 } // namespace base | 285 } // namespace base |
OLD | NEW |