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 // 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 | 11 |
12 #include <math.h> | 12 #include <math.h> |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/debug/alias.h" | 18 #include "base/debug/alias.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 21 #include "base/metrics/metrics_hashes.h" |
21 #include "base/metrics/sample_vector.h" | 22 #include "base/metrics/sample_vector.h" |
22 #include "base/metrics/statistics_recorder.h" | 23 #include "base/metrics/statistics_recorder.h" |
23 #include "base/pickle.h" | 24 #include "base/pickle.h" |
24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
25 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
26 #include "base/synchronization/lock.h" | 27 #include "base/synchronization/lock.h" |
27 #include "base/values.h" | 28 #include "base/values.h" |
28 | 29 |
29 namespace base { | 30 namespace base { |
30 | 31 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 253 |
253 if (*minimum >= *maximum) | 254 if (*minimum >= *maximum) |
254 return false; | 255 return false; |
255 if (*bucket_count < 3) | 256 if (*bucket_count < 3) |
256 return false; | 257 return false; |
257 if (*bucket_count > static_cast<size_t>(*maximum - *minimum + 2)) | 258 if (*bucket_count > static_cast<size_t>(*maximum - *minimum + 2)) |
258 return false; | 259 return false; |
259 return true; | 260 return true; |
260 } | 261 } |
261 | 262 |
| 263 uint64_t Histogram::id() const { |
| 264 return samples_->id(); |
| 265 } |
| 266 |
262 HistogramType Histogram::GetHistogramType() const { | 267 HistogramType Histogram::GetHistogramType() const { |
263 return HISTOGRAM; | 268 return HISTOGRAM; |
264 } | 269 } |
265 | 270 |
266 bool Histogram::HasConstructionArguments(Sample expected_minimum, | 271 bool Histogram::HasConstructionArguments(Sample expected_minimum, |
267 Sample expected_maximum, | 272 Sample expected_maximum, |
268 size_t expected_bucket_count) const { | 273 size_t expected_bucket_count) const { |
269 return ((expected_minimum == declared_min_) && | 274 return ((expected_minimum == declared_min_) && |
270 (expected_maximum == declared_max_) && | 275 (expected_maximum == declared_max_) && |
271 (expected_bucket_count == bucket_count())); | 276 (expected_bucket_count == bucket_count())); |
(...skipping 18 matching lines...) Expand all Loading... |
290 samples_->Accumulate(value, count); | 295 samples_->Accumulate(value, count); |
291 | 296 |
292 FindAndRunCallback(value); | 297 FindAndRunCallback(value); |
293 } | 298 } |
294 | 299 |
295 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { | 300 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { |
296 return SnapshotSampleVector().Pass(); | 301 return SnapshotSampleVector().Pass(); |
297 } | 302 } |
298 | 303 |
299 void Histogram::AddSamples(const HistogramSamples& samples) { | 304 void Histogram::AddSamples(const HistogramSamples& samples) { |
| 305 DCHECK(samples.id() == 0 || samples.id() == samples_->id()); |
300 samples_->Add(samples); | 306 samples_->Add(samples); |
301 } | 307 } |
302 | 308 |
303 bool Histogram::AddSamplesFromPickle(PickleIterator* iter) { | 309 bool Histogram::AddSamplesFromPickle(PickleIterator* iter) { |
304 return samples_->AddFromPickle(iter); | 310 return samples_->AddFromPickle(iter); |
305 } | 311 } |
306 | 312 |
307 // The following methods provide a graphical histogram display. | 313 // The following methods provide a graphical histogram display. |
308 void Histogram::WriteHTMLGraph(std::string* output) const { | 314 void Histogram::WriteHTMLGraph(std::string* output) const { |
309 // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc. | 315 // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc. |
(...skipping 18 matching lines...) Expand all Loading... |
328 | 334 |
329 Histogram::Histogram(const std::string& name, | 335 Histogram::Histogram(const std::string& name, |
330 Sample minimum, | 336 Sample minimum, |
331 Sample maximum, | 337 Sample maximum, |
332 const BucketRanges* ranges) | 338 const BucketRanges* ranges) |
333 : HistogramBase(name), | 339 : HistogramBase(name), |
334 bucket_ranges_(ranges), | 340 bucket_ranges_(ranges), |
335 declared_min_(minimum), | 341 declared_min_(minimum), |
336 declared_max_(maximum) { | 342 declared_max_(maximum) { |
337 if (ranges) | 343 if (ranges) |
338 samples_.reset(new SampleVector(ranges)); | 344 samples_.reset(new SampleVector(metrics::HashMetricName(name), ranges)); |
339 } | 345 } |
340 | 346 |
341 Histogram::~Histogram() { | 347 Histogram::~Histogram() { |
342 } | 348 } |
343 | 349 |
344 bool Histogram::PrintEmptyBucket(size_t index) const { | 350 bool Histogram::PrintEmptyBucket(size_t index) const { |
345 return true; | 351 return true; |
346 } | 352 } |
347 | 353 |
348 // Use the actual bucket widths (like a linear histogram) until the widths get | 354 // Use the actual bucket widths (like a linear histogram) until the widths get |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 histogram_name, declared_min, declared_max, bucket_count, flags); | 391 histogram_name, declared_min, declared_max, bucket_count, flags); |
386 | 392 |
387 if (!ValidateRangeChecksum(*histogram, range_checksum)) { | 393 if (!ValidateRangeChecksum(*histogram, range_checksum)) { |
388 // The serialized histogram might be corrupted. | 394 // The serialized histogram might be corrupted. |
389 return NULL; | 395 return NULL; |
390 } | 396 } |
391 return histogram; | 397 return histogram; |
392 } | 398 } |
393 | 399 |
394 scoped_ptr<SampleVector> Histogram::SnapshotSampleVector() const { | 400 scoped_ptr<SampleVector> Histogram::SnapshotSampleVector() const { |
395 scoped_ptr<SampleVector> samples(new SampleVector(bucket_ranges())); | 401 scoped_ptr<SampleVector> samples( |
| 402 new SampleVector(metrics::HashMetricName(histogram_name()), |
| 403 bucket_ranges())); |
396 samples->Add(*samples_); | 404 samples->Add(*samples_); |
397 return samples.Pass(); | 405 return samples.Pass(); |
398 } | 406 } |
399 | 407 |
400 void Histogram::WriteAsciiImpl(bool graph_it, | 408 void Histogram::WriteAsciiImpl(bool graph_it, |
401 const std::string& newline, | 409 const std::string& newline, |
402 std::string* output) const { | 410 std::string* output) const { |
403 // Get local (stack) copies of all effectively volatile class data so that we | 411 // Get local (stack) copies of all effectively volatile class data so that we |
404 // are consistent across our output activities. | 412 // are consistent across our output activities. |
405 scoped_ptr<SampleVector> snapshot = SnapshotSampleVector(); | 413 scoped_ptr<SampleVector> snapshot = SnapshotSampleVector(); |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 | 900 |
893 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 901 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
894 for (size_t i = 0; i < ranges.size(); i++) { | 902 for (size_t i = 0; i < ranges.size(); i++) { |
895 bucket_ranges->set_range(i, ranges[i]); | 903 bucket_ranges->set_range(i, ranges[i]); |
896 } | 904 } |
897 bucket_ranges->ResetChecksum(); | 905 bucket_ranges->ResetChecksum(); |
898 return bucket_ranges; | 906 return bucket_ranges; |
899 } | 907 } |
900 | 908 |
901 } // namespace base | 909 } // namespace base |
OLD | NEW |