OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/debug/leak_annotations.h" | |
18 #include "base/logging.h" | 17 #include "base/logging.h" |
19 #include "base/pickle.h" | 18 #include "base/pickle.h" |
20 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
21 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
22 | 21 |
23 namespace base { | 22 namespace base { |
24 | 23 |
25 // Static table of checksums for all possible 8 bit bytes. | 24 // Static table of checksums for all possible 8 bit bytes. |
26 const uint32 Histogram::kCrcTable[256] = {0x0, 0x77073096L, 0xee0e612cL, | 25 const uint32 Histogram::kCrcTable[256] = {0x0, 0x77073096L, 0xee0e612cL, |
27 0x990951baL, 0x76dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0xedb8832L, | 26 0x990951baL, 0x76dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0xedb8832L, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Extra variable is not needed... but this keeps this section basically | 90 // Extra variable is not needed... but this keeps this section basically |
92 // identical to other derived classes in this file (and compiler will | 91 // identical to other derived classes in this file (and compiler will |
93 // optimize away the extra variable. | 92 // optimize away the extra variable. |
94 // To avoid racy destruction at shutdown, the following will be leaked. | 93 // To avoid racy destruction at shutdown, the following will be leaked. |
95 Histogram* tentative_histogram = | 94 Histogram* tentative_histogram = |
96 new Histogram(name, minimum, maximum, bucket_count); | 95 new Histogram(name, minimum, maximum, bucket_count); |
97 tentative_histogram->InitializeBucketRange(); | 96 tentative_histogram->InitializeBucketRange(); |
98 tentative_histogram->SetFlags(flags); | 97 tentative_histogram->SetFlags(flags); |
99 histogram = | 98 histogram = |
100 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 99 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
101 if (histogram == tentative_histogram) | |
102 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 | |
103 } | 100 } |
104 | 101 |
105 DCHECK_EQ(HISTOGRAM, histogram->histogram_type()); | 102 DCHECK_EQ(HISTOGRAM, histogram->histogram_type()); |
106 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); | 103 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); |
107 return histogram; | 104 return histogram; |
108 } | 105 } |
109 | 106 |
110 Histogram* Histogram::FactoryTimeGet(const std::string& name, | 107 Histogram* Histogram::FactoryTimeGet(const std::string& name, |
111 TimeDelta minimum, | 108 TimeDelta minimum, |
112 TimeDelta maximum, | 109 TimeDelta maximum, |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 maximum = kSampleType_MAX - 1; | 784 maximum = kSampleType_MAX - 1; |
788 | 785 |
789 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { | 786 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { |
790 // To avoid racy destruction at shutdown, the following will be leaked. | 787 // To avoid racy destruction at shutdown, the following will be leaked. |
791 LinearHistogram* tentative_histogram = | 788 LinearHistogram* tentative_histogram = |
792 new LinearHistogram(name, minimum, maximum, bucket_count); | 789 new LinearHistogram(name, minimum, maximum, bucket_count); |
793 tentative_histogram->InitializeBucketRange(); | 790 tentative_histogram->InitializeBucketRange(); |
794 tentative_histogram->SetFlags(flags); | 791 tentative_histogram->SetFlags(flags); |
795 histogram = | 792 histogram = |
796 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 793 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
797 if (histogram == tentative_histogram) | |
798 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 | |
799 } | 794 } |
800 | 795 |
801 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type()); | 796 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type()); |
802 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); | 797 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); |
803 return histogram; | 798 return histogram; |
804 } | 799 } |
805 | 800 |
806 Histogram* LinearHistogram::FactoryTimeGet(const std::string& name, | 801 Histogram* LinearHistogram::FactoryTimeGet(const std::string& name, |
807 TimeDelta minimum, | 802 TimeDelta minimum, |
808 TimeDelta maximum, | 803 TimeDelta maximum, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 Histogram* BooleanHistogram::FactoryGet(const std::string& name, Flags flags) { | 875 Histogram* BooleanHistogram::FactoryGet(const std::string& name, Flags flags) { |
881 Histogram* histogram(NULL); | 876 Histogram* histogram(NULL); |
882 | 877 |
883 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { | 878 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { |
884 // To avoid racy destruction at shutdown, the following will be leaked. | 879 // To avoid racy destruction at shutdown, the following will be leaked. |
885 BooleanHistogram* tentative_histogram = new BooleanHistogram(name); | 880 BooleanHistogram* tentative_histogram = new BooleanHistogram(name); |
886 tentative_histogram->InitializeBucketRange(); | 881 tentative_histogram->InitializeBucketRange(); |
887 tentative_histogram->SetFlags(flags); | 882 tentative_histogram->SetFlags(flags); |
888 histogram = | 883 histogram = |
889 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 884 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
890 if (histogram == tentative_histogram) | |
891 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 | |
892 } | 885 } |
893 | 886 |
894 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type()); | 887 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type()); |
895 return histogram; | 888 return histogram; |
896 } | 889 } |
897 | 890 |
898 Histogram::ClassType BooleanHistogram::histogram_type() const { | 891 Histogram::ClassType BooleanHistogram::histogram_type() const { |
899 return BOOLEAN_HISTOGRAM; | 892 return BOOLEAN_HISTOGRAM; |
900 } | 893 } |
901 | 894 |
(...skipping 27 matching lines...) Expand all Loading... |
929 | 922 |
930 DCHECK_LT(ranges.back(), kSampleType_MAX); | 923 DCHECK_LT(ranges.back(), kSampleType_MAX); |
931 | 924 |
932 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { | 925 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { |
933 // To avoid racy destruction at shutdown, the following will be leaked. | 926 // To avoid racy destruction at shutdown, the following will be leaked. |
934 CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges); | 927 CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges); |
935 tentative_histogram->InitializedCustomBucketRange(ranges); | 928 tentative_histogram->InitializedCustomBucketRange(ranges); |
936 tentative_histogram->SetFlags(flags); | 929 tentative_histogram->SetFlags(flags); |
937 histogram = | 930 histogram = |
938 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 931 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
939 if (histogram == tentative_histogram) | |
940 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 | |
941 } | 932 } |
942 | 933 |
943 DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM); | 934 DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM); |
944 DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(), | 935 DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(), |
945 ranges.size())); | 936 ranges.size())); |
946 return histogram; | 937 return histogram; |
947 } | 938 } |
948 | 939 |
949 Histogram::ClassType CustomHistogram::histogram_type() const { | 940 Histogram::ClassType CustomHistogram::histogram_type() const { |
950 return CUSTOM_HISTOGRAM; | 941 return CUSTOM_HISTOGRAM; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 } | 1138 } |
1148 | 1139 |
1149 // static | 1140 // static |
1150 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 1141 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
1151 // static | 1142 // static |
1152 base::Lock* StatisticsRecorder::lock_ = NULL; | 1143 base::Lock* StatisticsRecorder::lock_ = NULL; |
1153 // static | 1144 // static |
1154 bool StatisticsRecorder::dump_on_exit_ = false; | 1145 bool StatisticsRecorder::dump_on_exit_ = false; |
1155 | 1146 |
1156 } // namespace base | 1147 } // namespace base |
OLD | NEW |