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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 std::unique_ptr<HistogramSamples> SparseHistogram::SnapshotSamples() const { | 120 std::unique_ptr<HistogramSamples> SparseHistogram::SnapshotSamples() const { |
121 std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash())); | 121 std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash())); |
122 | 122 |
123 base::AutoLock auto_lock(lock_); | 123 base::AutoLock auto_lock(lock_); |
124 snapshot->Add(*samples_); | 124 snapshot->Add(*samples_); |
125 return std::move(snapshot); | 125 return std::move(snapshot); |
126 } | 126 } |
127 | 127 |
128 std::unique_ptr<HistogramSamples> SparseHistogram::SnapshotDelta() { | 128 std::unique_ptr<HistogramSamples> SparseHistogram::SnapshotDelta() { |
| 129 DCHECK(!final_delta_created_); |
| 130 |
129 std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash())); | 131 std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash())); |
130 base::AutoLock auto_lock(lock_); | 132 base::AutoLock auto_lock(lock_); |
131 snapshot->Add(*samples_); | 133 snapshot->Add(*samples_); |
132 | 134 |
133 // Subtract what was previously logged and update that information. | 135 // Subtract what was previously logged and update that information. |
134 snapshot->Subtract(*logged_samples_); | 136 snapshot->Subtract(*logged_samples_); |
135 logged_samples_->Add(*snapshot); | 137 logged_samples_->Add(*snapshot); |
136 return std::move(snapshot); | 138 return std::move(snapshot); |
137 } | 139 } |
138 | 140 |
| 141 std::unique_ptr<HistogramSamples> SparseHistogram::SnapshotFinalDelta() const { |
| 142 DCHECK(!final_delta_created_); |
| 143 final_delta_created_ = true; |
| 144 |
| 145 std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash())); |
| 146 base::AutoLock auto_lock(lock_); |
| 147 snapshot->Add(*samples_); |
| 148 |
| 149 // Subtract what was previously logged and then return. |
| 150 snapshot->Subtract(*logged_samples_); |
| 151 return std::move(snapshot); |
| 152 } |
| 153 |
139 void SparseHistogram::AddSamples(const HistogramSamples& samples) { | 154 void SparseHistogram::AddSamples(const HistogramSamples& samples) { |
140 base::AutoLock auto_lock(lock_); | 155 base::AutoLock auto_lock(lock_); |
141 samples_->Add(samples); | 156 samples_->Add(samples); |
142 } | 157 } |
143 | 158 |
144 bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) { | 159 bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) { |
145 base::AutoLock auto_lock(lock_); | 160 base::AutoLock auto_lock(lock_); |
146 return samples_->AddFromPickle(iter); | 161 return samples_->AddFromPickle(iter); |
147 } | 162 } |
148 | 163 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 std::string* output) const { | 281 std::string* output) const { |
267 StringAppendF(output, | 282 StringAppendF(output, |
268 "Histogram: %s recorded %d samples", | 283 "Histogram: %s recorded %d samples", |
269 histogram_name().c_str(), | 284 histogram_name().c_str(), |
270 total_count); | 285 total_count); |
271 if (flags() & ~kHexRangePrintingFlag) | 286 if (flags() & ~kHexRangePrintingFlag) |
272 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); | 287 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); |
273 } | 288 } |
274 | 289 |
275 } // namespace base | 290 } // namespace base |
OLD | NEW |