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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } | 100 } |
102 | 101 |
103 DCHECK_EQ(HISTOGRAM, histogram->histogram_type()); | 102 DCHECK_EQ(HISTOGRAM, histogram->histogram_type()); |
104 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); | 103 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); |
105 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 | |
106 return histogram; | 104 return histogram; |
107 } | 105 } |
108 | 106 |
109 Histogram* Histogram::FactoryTimeGet(const std::string& name, | 107 Histogram* Histogram::FactoryTimeGet(const std::string& name, |
110 TimeDelta minimum, | 108 TimeDelta minimum, |
111 TimeDelta maximum, | 109 TimeDelta maximum, |
112 size_t bucket_count, | 110 size_t bucket_count, |
113 Flags flags) { | 111 Flags flags) { |
114 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(), | 112 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(), |
115 bucket_count, flags); | 113 bucket_count, flags); |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 LinearHistogram* tentative_histogram = | 788 LinearHistogram* tentative_histogram = |
791 new LinearHistogram(name, minimum, maximum, bucket_count); | 789 new LinearHistogram(name, minimum, maximum, bucket_count); |
792 tentative_histogram->InitializeBucketRange(); | 790 tentative_histogram->InitializeBucketRange(); |
793 tentative_histogram->SetFlags(flags); | 791 tentative_histogram->SetFlags(flags); |
794 histogram = | 792 histogram = |
795 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 793 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
796 } | 794 } |
797 | 795 |
798 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type()); | 796 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type()); |
799 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); | 797 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); |
800 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 | |
801 return histogram; | 798 return histogram; |
802 } | 799 } |
803 | 800 |
804 Histogram* LinearHistogram::FactoryTimeGet(const std::string& name, | 801 Histogram* LinearHistogram::FactoryTimeGet(const std::string& name, |
805 TimeDelta minimum, | 802 TimeDelta minimum, |
806 TimeDelta maximum, | 803 TimeDelta maximum, |
807 size_t bucket_count, | 804 size_t bucket_count, |
808 Flags flags) { | 805 Flags flags) { |
809 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(), | 806 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(), |
810 bucket_count, flags); | 807 bucket_count, flags); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { | 878 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { |
882 // To avoid racy destruction at shutdown, the following will be leaked. | 879 // To avoid racy destruction at shutdown, the following will be leaked. |
883 BooleanHistogram* tentative_histogram = new BooleanHistogram(name); | 880 BooleanHistogram* tentative_histogram = new BooleanHistogram(name); |
884 tentative_histogram->InitializeBucketRange(); | 881 tentative_histogram->InitializeBucketRange(); |
885 tentative_histogram->SetFlags(flags); | 882 tentative_histogram->SetFlags(flags); |
886 histogram = | 883 histogram = |
887 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 884 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
888 } | 885 } |
889 | 886 |
890 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type()); | 887 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type()); |
891 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 | |
892 return histogram; | 888 return histogram; |
893 } | 889 } |
894 | 890 |
895 Histogram::ClassType BooleanHistogram::histogram_type() const { | 891 Histogram::ClassType BooleanHistogram::histogram_type() const { |
896 return BOOLEAN_HISTOGRAM; | 892 return BOOLEAN_HISTOGRAM; |
897 } | 893 } |
898 | 894 |
899 void BooleanHistogram::AddBoolean(bool value) { | 895 void BooleanHistogram::AddBoolean(bool value) { |
900 Add(value ? 1 : 0); | 896 Add(value ? 1 : 0); |
901 } | 897 } |
(...skipping 29 matching lines...) Expand all Loading... |
931 CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges); | 927 CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges); |
932 tentative_histogram->InitializedCustomBucketRange(ranges); | 928 tentative_histogram->InitializedCustomBucketRange(ranges); |
933 tentative_histogram->SetFlags(flags); | 929 tentative_histogram->SetFlags(flags); |
934 histogram = | 930 histogram = |
935 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 931 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
936 } | 932 } |
937 | 933 |
938 DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM); | 934 DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM); |
939 DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(), | 935 DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(), |
940 ranges.size())); | 936 ranges.size())); |
941 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 | |
942 return histogram; | 937 return histogram; |
943 } | 938 } |
944 | 939 |
945 Histogram::ClassType CustomHistogram::histogram_type() const { | 940 Histogram::ClassType CustomHistogram::histogram_type() const { |
946 return CUSTOM_HISTOGRAM; | 941 return CUSTOM_HISTOGRAM; |
947 } | 942 } |
948 | 943 |
949 // static | 944 // static |
950 std::vector<Histogram::Sample> CustomHistogram::ArrayToCustomRanges( | 945 std::vector<Histogram::Sample> CustomHistogram::ArrayToCustomRanges( |
951 const Sample* values, size_t num_values) { | 946 const Sample* values, size_t num_values) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 } | 1138 } |
1144 | 1139 |
1145 // static | 1140 // static |
1146 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 1141 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
1147 // static | 1142 // static |
1148 base::Lock* StatisticsRecorder::lock_ = NULL; | 1143 base::Lock* StatisticsRecorder::lock_ = NULL; |
1149 // static | 1144 // static |
1150 bool StatisticsRecorder::dump_on_exit_ = false; | 1145 bool StatisticsRecorder::dump_on_exit_ = false; |
1151 | 1146 |
1152 } // namespace base | 1147 } // namespace base |
OLD | NEW |