OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Histogram is an object that aggregates statistics, and can summarize them in | 5 // Histogram is an object that aggregates statistics, and can summarize them in |
6 // various forms, including ASCII graphical, HTML, and numerically (as a | 6 // various forms, including ASCII graphical, HTML, and numerically (as a |
7 // vector of numbers corresponding to each of the aggregating buckets). | 7 // vector of numbers corresponding to each of the aggregating buckets). |
8 // See header file for details and examples. | 8 // See header file for details and examples. |
9 | 9 |
10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 117 } |
118 | 118 |
119 int64 remaining = sample_count; | 119 int64 remaining = sample_count; |
120 int64 past = 0; | 120 int64 past = 0; |
121 // Output the actual histogram graph. | 121 // Output the actual histogram graph. |
122 for (size_t i = 0; i < bucket_count(); ++i) { | 122 for (size_t i = 0; i < bucket_count(); ++i) { |
123 Count current = snapshot.counts(i); | 123 Count current = snapshot.counts(i); |
124 if (!current && !PrintEmptyBucket(i)) | 124 if (!current && !PrintEmptyBucket(i)) |
125 continue; | 125 continue; |
126 remaining -= current; | 126 remaining -= current; |
127 StringAppendF(output, "%#*s ", print_width, GetAsciiBucketRange(i).c_str()); | 127 std::string range = GetAsciiBucketRange(i); |
| 128 output->append(range); |
| 129 for (size_t j = 0; range.size() + j < print_width + 1; ++j) |
| 130 output->push_back(' '); |
128 if (0 == current && i < bucket_count() - 1 && 0 == snapshot.counts(i + 1)) { | 131 if (0 == current && i < bucket_count() - 1 && 0 == snapshot.counts(i + 1)) { |
129 while (i < bucket_count() - 1 && 0 == snapshot.counts(i + 1)) | 132 while (i < bucket_count() - 1 && 0 == snapshot.counts(i + 1)) |
130 ++i; | 133 ++i; |
131 output->append("... "); | 134 output->append("... "); |
132 output->append(newline); | 135 output->append(newline); |
133 continue; // No reason to plot emptiness. | 136 continue; // No reason to plot emptiness. |
134 } | 137 } |
135 double current_size = GetBucketSize(current, i); | 138 double current_size = GetBucketSize(current, i); |
136 if (graph_it) | 139 if (graph_it) |
137 WriteAsciiBucketGraph(current_size, max_size, output); | 140 WriteAsciiBucketGraph(current_size, max_size, output); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 if (current_size > max) | 283 if (current_size > max) |
281 max = current_size; | 284 max = current_size; |
282 } | 285 } |
283 return max; | 286 return max; |
284 } | 287 } |
285 | 288 |
286 void Histogram::WriteAsciiHeader(const SampleSet& snapshot, | 289 void Histogram::WriteAsciiHeader(const SampleSet& snapshot, |
287 Count sample_count, | 290 Count sample_count, |
288 std::string* output) const { | 291 std::string* output) const { |
289 StringAppendF(output, | 292 StringAppendF(output, |
290 "Histogram: %s recorded %ld samples", | 293 "Histogram: %s recorded %d samples", |
291 histogram_name().c_str(), | 294 histogram_name().c_str(), |
292 sample_count); | 295 sample_count); |
293 if (0 == sample_count) { | 296 if (0 == sample_count) { |
294 DCHECK(0 == snapshot.sum()); | 297 DCHECK(0 == snapshot.sum()); |
295 } else { | 298 } else { |
296 double average = static_cast<float>(snapshot.sum()) / sample_count; | 299 double average = static_cast<float>(snapshot.sum()) / sample_count; |
297 double variance = static_cast<float>(snapshot.square_sum())/sample_count | 300 double variance = static_cast<float>(snapshot.square_sum())/sample_count |
298 - average * average; | 301 - average * average; |
299 double standard_deviation = sqrt(variance); | 302 double standard_deviation = sqrt(variance); |
300 | 303 |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 snapshot->push_back(it->second); | 767 snapshot->push_back(it->second); |
765 } | 768 } |
766 } | 769 } |
767 | 770 |
768 // static | 771 // static |
769 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 772 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
770 // static | 773 // static |
771 Lock* StatisticsRecorder::lock_ = NULL; | 774 Lock* StatisticsRecorder::lock_ = NULL; |
772 // static | 775 // static |
773 bool StatisticsRecorder::dump_on_exit_ = false; | 776 bool StatisticsRecorder::dump_on_exit_ = false; |
OLD | NEW |