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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 void SparseHistogram::AddSamples(const HistogramSamples& samples) { | 154 void SparseHistogram::AddSamples(const HistogramSamples& samples) { |
155 base::AutoLock auto_lock(lock_); | 155 base::AutoLock auto_lock(lock_); |
156 samples_->Add(samples); | 156 samples_->Add(samples); |
157 } | 157 } |
158 | 158 |
159 bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) { | 159 bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) { |
160 base::AutoLock auto_lock(lock_); | 160 base::AutoLock auto_lock(lock_); |
161 return samples_->AddFromPickle(iter); | 161 return samples_->AddFromPickle(iter); |
162 } | 162 } |
163 | 163 |
164 void SparseHistogram::WriteHTMLGraph(std::string* output) const { | 164 void SparseHistogram::WriteHTMLGraph(const HistogramSamples* snapshot, |
| 165 std::string* output) const { |
165 output->append("<PRE>"); | 166 output->append("<PRE>"); |
166 WriteAsciiImpl(true, "<br>", output); | 167 WriteAsciiImpl(true, "<br>", snapshot, output); |
167 output->append("</PRE>"); | 168 output->append("</PRE>"); |
168 } | 169 } |
169 | 170 |
170 void SparseHistogram::WriteAscii(std::string* output) const { | 171 void SparseHistogram::WriteAscii(const HistogramSamples* snapshot, |
171 WriteAsciiImpl(true, "\n", output); | 172 std::string* output) const { |
| 173 WriteAsciiImpl(true, "\n", snapshot, output); |
172 } | 174 } |
173 | 175 |
174 bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const { | 176 bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const { |
175 return pickle->WriteString(histogram_name()) && pickle->WriteInt(flags()); | 177 return pickle->WriteString(histogram_name()) && pickle->WriteInt(flags()); |
176 } | 178 } |
177 | 179 |
178 SparseHistogram::SparseHistogram(const std::string& name) | 180 SparseHistogram::SparseHistogram(const std::string& name) |
179 : HistogramBase(name), | 181 : HistogramBase(name), |
180 samples_(new SampleMap(HashMetricName(name))), | 182 samples_(new SampleMap(HashMetricName(name))), |
181 logged_samples_(new SampleMap(samples_->id())) {} | 183 logged_samples_(new SampleMap(samples_->id())) {} |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } | 221 } |
220 | 222 |
221 void SparseHistogram::GetCountAndBucketData(Count* count, | 223 void SparseHistogram::GetCountAndBucketData(Count* count, |
222 int64_t* sum, | 224 int64_t* sum, |
223 ListValue* buckets) const { | 225 ListValue* buckets) const { |
224 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.) | 226 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.) |
225 } | 227 } |
226 | 228 |
227 void SparseHistogram::WriteAsciiImpl(bool graph_it, | 229 void SparseHistogram::WriteAsciiImpl(bool graph_it, |
228 const std::string& newline, | 230 const std::string& newline, |
| 231 const HistogramSamples* snapshot, |
229 std::string* output) const { | 232 std::string* output) const { |
230 // Get a local copy of the data so we are consistent. | 233 std::unique_ptr<HistogramSamples> local_snapshot; |
231 std::unique_ptr<HistogramSamples> snapshot = SnapshotSamples(); | 234 if (!snapshot) { |
| 235 // Get local (stack) copies of all effectively volatile class data so |
| 236 // that we are consistent across our output activities. |
| 237 local_snapshot = SnapshotSamples(); |
| 238 snapshot = local_snapshot.get(); |
| 239 } |
232 Count total_count = snapshot->TotalCount(); | 240 Count total_count = snapshot->TotalCount(); |
233 double scaled_total_count = total_count / 100.0; | 241 double scaled_total_count = total_count / 100.0; |
234 | 242 |
235 WriteAsciiHeader(total_count, output); | 243 WriteAsciiHeader(total_count, output); |
236 output->append(newline); | 244 output->append(newline); |
237 | 245 |
238 // Determine how wide the largest bucket range is (how many digits to print), | 246 // Determine how wide the largest bucket range is (how many digits to print), |
239 // so that we'll be able to right-align starts for the graphical bars. | 247 // so that we'll be able to right-align starts for the graphical bars. |
240 // Determine which bucket has the largest sample count so that we can | 248 // Determine which bucket has the largest sample count so that we can |
241 // normalize the graphical bar-width relative to that sample count. | 249 // normalize the graphical bar-width relative to that sample count. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 std::string* output) const { | 289 std::string* output) const { |
282 StringAppendF(output, | 290 StringAppendF(output, |
283 "Histogram: %s recorded %d samples", | 291 "Histogram: %s recorded %d samples", |
284 histogram_name().c_str(), | 292 histogram_name().c_str(), |
285 total_count); | 293 total_count); |
286 if (flags() & ~kHexRangePrintingFlag) | 294 if (flags() & ~kHexRangePrintingFlag) |
287 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); | 295 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); |
288 } | 296 } |
289 | 297 |
290 } // namespace base | 298 } // namespace base |
OLD | NEW |