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::name_hash() 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 333 |
329 Histogram::Histogram(const std::string& name, | 334 Histogram::Histogram(const std::string& name, |
330 Sample minimum, | 335 Sample minimum, |
331 Sample maximum, | 336 Sample maximum, |
332 const BucketRanges* ranges) | 337 const BucketRanges* ranges) |
333 : HistogramBase(name), | 338 : HistogramBase(name), |
334 bucket_ranges_(ranges), | 339 bucket_ranges_(ranges), |
335 declared_min_(minimum), | 340 declared_min_(minimum), |
336 declared_max_(maximum) { | 341 declared_max_(maximum) { |
337 if (ranges) | 342 if (ranges) |
338 samples_.reset(new SampleVector(ranges)); | 343 samples_.reset(new SampleVector(HashMetricName(name), ranges)); |
339 } | 344 } |
340 | 345 |
341 Histogram::~Histogram() { | 346 Histogram::~Histogram() { |
342 } | 347 } |
343 | 348 |
344 bool Histogram::PrintEmptyBucket(size_t index) const { | 349 bool Histogram::PrintEmptyBucket(size_t index) const { |
345 return true; | 350 return true; |
346 } | 351 } |
347 | 352 |
348 // Use the actual bucket widths (like a linear histogram) until the widths get | 353 // 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); | 390 histogram_name, declared_min, declared_max, bucket_count, flags); |
386 | 391 |
387 if (!ValidateRangeChecksum(*histogram, range_checksum)) { | 392 if (!ValidateRangeChecksum(*histogram, range_checksum)) { |
388 // The serialized histogram might be corrupted. | 393 // The serialized histogram might be corrupted. |
389 return NULL; | 394 return NULL; |
390 } | 395 } |
391 return histogram; | 396 return histogram; |
392 } | 397 } |
393 | 398 |
394 scoped_ptr<SampleVector> Histogram::SnapshotSampleVector() const { | 399 scoped_ptr<SampleVector> Histogram::SnapshotSampleVector() const { |
395 scoped_ptr<SampleVector> samples(new SampleVector(bucket_ranges())); | 400 scoped_ptr<SampleVector> samples( |
| 401 new SampleVector(samples_->id(), bucket_ranges())); |
396 samples->Add(*samples_); | 402 samples->Add(*samples_); |
397 return samples; | 403 return samples; |
398 } | 404 } |
399 | 405 |
400 void Histogram::WriteAsciiImpl(bool graph_it, | 406 void Histogram::WriteAsciiImpl(bool graph_it, |
401 const std::string& newline, | 407 const std::string& newline, |
402 std::string* output) const { | 408 std::string* output) const { |
403 // Get local (stack) copies of all effectively volatile class data so that we | 409 // Get local (stack) copies of all effectively volatile class data so that we |
404 // are consistent across our output activities. | 410 // are consistent across our output activities. |
405 scoped_ptr<SampleVector> snapshot = SnapshotSampleVector(); | 411 scoped_ptr<SampleVector> snapshot = SnapshotSampleVector(); |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 | 898 |
893 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 899 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
894 for (size_t i = 0; i < ranges.size(); i++) { | 900 for (size_t i = 0; i < ranges.size(); i++) { |
895 bucket_ranges->set_range(i, ranges[i]); | 901 bucket_ranges->set_range(i, ranges[i]); |
896 } | 902 } |
897 bucket_ranges->ResetChecksum(); | 903 bucket_ranges->ResetChecksum(); |
898 return bucket_ranges; | 904 return bucket_ranges; |
899 } | 905 } |
900 | 906 |
901 } // namespace base | 907 } // namespace base |
OLD | NEW |