Chromium Code Reviews| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 void SparseHistogram::AddSamples(const HistogramSamples& samples) { | 139 void SparseHistogram::AddSamples(const HistogramSamples& samples) { |
| 140 base::AutoLock auto_lock(lock_); | 140 base::AutoLock auto_lock(lock_); |
| 141 samples_->Add(samples); | 141 samples_->Add(samples); |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) { | 144 bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) { |
| 145 base::AutoLock auto_lock(lock_); | 145 base::AutoLock auto_lock(lock_); |
| 146 return samples_->AddFromPickle(iter); | 146 return samples_->AddFromPickle(iter); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void SparseHistogram::WriteHTMLGraph(std::string* output) const { | 149 void SparseHistogram::WriteHTMLGraph(const HistogramSamples* snapshot, |
| 150 std::string* output) const { | |
| 150 output->append("<PRE>"); | 151 output->append("<PRE>"); |
| 151 WriteAsciiImpl(true, "<br>", output); | 152 WriteAsciiImpl(true, "<br>", snapshot, output); |
| 152 output->append("</PRE>"); | 153 output->append("</PRE>"); |
| 153 } | 154 } |
| 154 | 155 |
| 155 void SparseHistogram::WriteAscii(std::string* output) const { | 156 void SparseHistogram::WriteAscii(const HistogramSamples* snapshot, |
| 156 WriteAsciiImpl(true, "\n", output); | 157 std::string* output) const { |
| 158 WriteAsciiImpl(true, "\n", snapshot, output); | |
| 157 } | 159 } |
| 158 | 160 |
| 159 bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const { | 161 bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const { |
| 160 return pickle->WriteString(histogram_name()) && pickle->WriteInt(flags()); | 162 return pickle->WriteString(histogram_name()) && pickle->WriteInt(flags()); |
| 161 } | 163 } |
| 162 | 164 |
| 163 SparseHistogram::SparseHistogram(const std::string& name) | 165 SparseHistogram::SparseHistogram(const std::string& name) |
| 164 : HistogramBase(name), | 166 : HistogramBase(name), |
| 165 samples_(new SampleMap(HashMetricName(name))), | 167 samples_(new SampleMap(HashMetricName(name))), |
| 166 logged_samples_(new SampleMap(samples_->id())) {} | 168 logged_samples_(new SampleMap(samples_->id())) {} |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 } | 206 } |
| 205 | 207 |
| 206 void SparseHistogram::GetCountAndBucketData(Count* count, | 208 void SparseHistogram::GetCountAndBucketData(Count* count, |
| 207 int64_t* sum, | 209 int64_t* sum, |
| 208 ListValue* buckets) const { | 210 ListValue* buckets) const { |
| 209 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.) | 211 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.) |
| 210 } | 212 } |
| 211 | 213 |
| 212 void SparseHistogram::WriteAsciiImpl(bool graph_it, | 214 void SparseHistogram::WriteAsciiImpl(bool graph_it, |
| 213 const std::string& newline, | 215 const std::string& newline, |
| 216 const HistogramSamples* snapshot, | |
| 214 std::string* output) const { | 217 std::string* output) const { |
| 215 // Get a local copy of the data so we are consistent. | 218 // Get a local copy of the data so we are consistent. |
|
Ilya Sherman
2016/04/13 00:29:32
Ditto
bcwhite
2016/04/13 11:58:18
Done.
| |
| 216 std::unique_ptr<HistogramSamples> snapshot = SnapshotSamples(); | 219 std::unique_ptr<HistogramSamples> local_snapshot; |
| 220 if (!snapshot) { | |
| 221 local_snapshot = SnapshotSamples(); | |
| 222 snapshot = local_snapshot.get(); | |
| 223 } | |
| 217 Count total_count = snapshot->TotalCount(); | 224 Count total_count = snapshot->TotalCount(); |
| 218 double scaled_total_count = total_count / 100.0; | 225 double scaled_total_count = total_count / 100.0; |
| 219 | 226 |
| 220 WriteAsciiHeader(total_count, output); | 227 WriteAsciiHeader(total_count, output); |
| 221 output->append(newline); | 228 output->append(newline); |
| 222 | 229 |
| 223 // Determine how wide the largest bucket range is (how many digits to print), | 230 // Determine how wide the largest bucket range is (how many digits to print), |
| 224 // so that we'll be able to right-align starts for the graphical bars. | 231 // so that we'll be able to right-align starts for the graphical bars. |
| 225 // Determine which bucket has the largest sample count so that we can | 232 // Determine which bucket has the largest sample count so that we can |
| 226 // normalize the graphical bar-width relative to that sample count. | 233 // normalize the graphical bar-width relative to that sample count. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 std::string* output) const { | 273 std::string* output) const { |
| 267 StringAppendF(output, | 274 StringAppendF(output, |
| 268 "Histogram: %s recorded %d samples", | 275 "Histogram: %s recorded %d samples", |
| 269 histogram_name().c_str(), | 276 histogram_name().c_str(), |
| 270 total_count); | 277 total_count); |
| 271 if (flags() & ~kHexRangePrintingFlag) | 278 if (flags() & ~kHexRangePrintingFlag) |
| 272 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); | 279 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); |
| 273 } | 280 } |
| 274 | 281 |
| 275 } // namespace base | 282 } // namespace base |
| OLD | NEW |