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" |
11 | 11 |
12 #include <math.h> | 12 #include <math.h> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 | 18 |
19 using base::TimeDelta; | 19 using base::TimeDelta; |
20 | 20 |
21 typedef Histogram::Count Count; | 21 typedef Histogram::Count Count; |
22 | 22 |
23 // static | 23 // static |
24 const int Histogram::kHexRangePrintingFlag = 0x8000; | 24 const int Histogram::kHexRangePrintingFlag = 0x8000; |
25 | 25 |
26 Histogram::Histogram(const wchar_t* name, Sample minimum, | 26 Histogram::Histogram(const char* name, Sample minimum, |
27 Sample maximum, size_t bucket_count) | 27 Sample maximum, size_t bucket_count) |
28 : StatsRate(WideToASCII(name).c_str()), | 28 : StatsRate(name), |
29 histogram_name_(WideToASCII(name)), | 29 histogram_name_(name), |
30 declared_min_(minimum), | 30 declared_min_(minimum), |
31 declared_max_(maximum), | 31 declared_max_(maximum), |
32 bucket_count_(bucket_count), | 32 bucket_count_(bucket_count), |
33 flags_(0), | 33 flags_(0), |
34 ranges_(bucket_count + 1, 0), | 34 ranges_(bucket_count + 1, 0), |
35 sample_(), | 35 sample_(), |
36 registered_(false) { | 36 registered_(false) { |
37 Initialize(); | 37 Initialize(); |
38 } | 38 } |
39 | 39 |
40 Histogram::Histogram(const wchar_t* name, TimeDelta minimum, | 40 Histogram::Histogram(const char* name, TimeDelta minimum, |
41 TimeDelta maximum, size_t bucket_count) | 41 TimeDelta maximum, size_t bucket_count) |
42 : StatsRate(WideToASCII(name).c_str()), | 42 : StatsRate(name), |
43 histogram_name_(WideToASCII(name)), | 43 histogram_name_(name), |
44 declared_min_(static_cast<int> (minimum.InMilliseconds())), | 44 declared_min_(static_cast<int> (minimum.InMilliseconds())), |
45 declared_max_(static_cast<int> (maximum.InMilliseconds())), | 45 declared_max_(static_cast<int> (maximum.InMilliseconds())), |
46 bucket_count_(bucket_count), | 46 bucket_count_(bucket_count), |
47 flags_(0), | 47 flags_(0), |
48 ranges_(bucket_count + 1, 0), | 48 ranges_(bucket_count + 1, 0), |
49 sample_(), | 49 sample_(), |
50 registered_(false) { | 50 registered_(false) { |
51 Initialize(); | 51 Initialize(); |
52 } | 52 } |
53 | 53 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 counts_[index] -= other.counts_[index]; | 408 counts_[index] -= other.counts_[index]; |
409 DCHECK(counts_[index] >= 0); | 409 DCHECK(counts_[index] >= 0); |
410 } | 410 } |
411 } | 411 } |
412 | 412 |
413 //------------------------------------------------------------------------------ | 413 //------------------------------------------------------------------------------ |
414 // LinearHistogram: This histogram uses a traditional set of evenly spaced | 414 // LinearHistogram: This histogram uses a traditional set of evenly spaced |
415 // buckets. | 415 // buckets. |
416 //------------------------------------------------------------------------------ | 416 //------------------------------------------------------------------------------ |
417 | 417 |
418 LinearHistogram::LinearHistogram(const wchar_t* name, | 418 LinearHistogram::LinearHistogram(const char* name, |
419 Sample minimum, Sample maximum, size_t bucket_count) | 419 Sample minimum, Sample maximum, size_t bucket_count) |
420 : Histogram(name, minimum >= 1 ? minimum : 1, maximum, bucket_count) { | 420 : Histogram(name, minimum >= 1 ? minimum : 1, maximum, bucket_count) { |
421 InitializeBucketRange(); | 421 InitializeBucketRange(); |
422 DCHECK(ValidateBucketRanges()); | 422 DCHECK(ValidateBucketRanges()); |
423 } | 423 } |
424 | 424 |
425 LinearHistogram::LinearHistogram(const wchar_t* name, | 425 LinearHistogram::LinearHistogram(const char* name, |
426 TimeDelta minimum, TimeDelta maximum, size_t bucket_count) | 426 TimeDelta minimum, TimeDelta maximum, size_t bucket_count) |
427 : Histogram(name, minimum >= TimeDelta::FromMilliseconds(1) ? | 427 : Histogram(name, minimum >= TimeDelta::FromMilliseconds(1) ? |
428 minimum : TimeDelta::FromMilliseconds(1), | 428 minimum : TimeDelta::FromMilliseconds(1), |
429 maximum, bucket_count) { | 429 maximum, bucket_count) { |
430 // Do a "better" (different) job at init than a base classes did... | 430 // Do a "better" (different) job at init than a base classes did... |
431 InitializeBucketRange(); | 431 InitializeBucketRange(); |
432 DCHECK(ValidateBucketRanges()); | 432 DCHECK(ValidateBucketRanges()); |
433 } | 433 } |
434 | 434 |
435 void LinearHistogram::SetRangeDescriptions( | 435 void LinearHistogram::SetRangeDescriptions( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 // Adjacent buckets with different widths would have "surprisingly" many (few) | 480 // Adjacent buckets with different widths would have "surprisingly" many (few) |
481 // samples in a histogram if we didn't normalize this way. | 481 // samples in a histogram if we didn't normalize this way. |
482 double denominator = ranges(i + 1) - ranges(i); | 482 double denominator = ranges(i + 1) - ranges(i); |
483 return current/denominator; | 483 return current/denominator; |
484 } | 484 } |
485 | 485 |
486 //------------------------------------------------------------------------------ | 486 //------------------------------------------------------------------------------ |
487 // This section provides implementation for ThreadSafeHistogram. | 487 // This section provides implementation for ThreadSafeHistogram. |
488 //------------------------------------------------------------------------------ | 488 //------------------------------------------------------------------------------ |
489 | 489 |
490 ThreadSafeHistogram::ThreadSafeHistogram(const wchar_t* name, Sample minimum, | 490 ThreadSafeHistogram::ThreadSafeHistogram(const char* name, Sample minimum, |
491 Sample maximum, size_t bucket_count) | 491 Sample maximum, size_t bucket_count) |
492 : Histogram(name, minimum, maximum, bucket_count), | 492 : Histogram(name, minimum, maximum, bucket_count), |
493 lock_() { | 493 lock_() { |
494 } | 494 } |
495 | 495 |
496 void ThreadSafeHistogram::Remove(int value) { | 496 void ThreadSafeHistogram::Remove(int value) { |
497 if (value >= kSampleType_MAX) | 497 if (value >= kSampleType_MAX) |
498 value = kSampleType_MAX - 1; | 498 value = kSampleType_MAX - 1; |
499 StatsRate::Add(-value); | 499 StatsRate::Add(-value); |
500 size_t index = BucketIndex(value); | 500 size_t index = BucketIndex(value); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 snapshot->push_back(it->second); | 643 snapshot->push_back(it->second); |
644 } | 644 } |
645 } | 645 } |
646 | 646 |
647 // static | 647 // static |
648 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 648 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
649 // static | 649 // static |
650 Lock* StatisticsRecorder::lock_ = NULL; | 650 Lock* StatisticsRecorder::lock_ = NULL; |
651 // static | 651 // static |
652 bool StatisticsRecorder::dump_on_exit_ = false; | 652 bool StatisticsRecorder::dump_on_exit_ = false; |
653 | |
OLD | NEW |