Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: base/histogram.h

Issue 2873009: Safeguard histogram accesses against null pointers.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8
9 // It supports calls to accumulate either time intervals (which are processed 9 // It supports calls to accumulate either time intervals (which are processed
10 // as integral number of milliseconds), or arbitrary integral units. 10 // as integral number of milliseconds), or arbitrary integral units.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #define HISTOGRAM_COUNTS_100(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ 54 #define HISTOGRAM_COUNTS_100(name, sample) HISTOGRAM_CUSTOM_COUNTS( \
55 name, sample, 1, 100, 50) 55 name, sample, 1, 100, 50)
56 56
57 #define HISTOGRAM_COUNTS_10000(name, sample) HISTOGRAM_CUSTOM_COUNTS( \ 57 #define HISTOGRAM_COUNTS_10000(name, sample) HISTOGRAM_CUSTOM_COUNTS( \
58 name, sample, 1, 10000, 50) 58 name, sample, 1, 10000, 50)
59 59
60 #define HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \ 60 #define HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \
61 static scoped_refptr<Histogram> counter = Histogram::FactoryGet( \ 61 static scoped_refptr<Histogram> counter = Histogram::FactoryGet( \
62 name, min, max, bucket_count, Histogram::kNoFlags); \ 62 name, min, max, bucket_count, Histogram::kNoFlags); \
63 DCHECK_EQ(name, counter->histogram_name()); \ 63 DCHECK_EQ(name, counter->histogram_name()); \
64 counter->Add(sample); \ 64 if (counter.get()) counter->Add(sample); \
65 } while (0) 65 } while (0)
66 66
67 #define HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ 67 #define HISTOGRAM_PERCENTAGE(name, under_one_hundred) \
68 HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) 68 HISTOGRAM_ENUMERATION(name, under_one_hundred, 101)
69 69
70 // For folks that need real specific times, use this to select a precise range 70 // For folks that need real specific times, use this to select a precise range
71 // of times you want plotted, and the number of buckets you want used. 71 // of times you want plotted, and the number of buckets you want used.
72 #define HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \ 72 #define HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \
73 static scoped_refptr<Histogram> counter = Histogram::FactoryTimeGet( \ 73 static scoped_refptr<Histogram> counter = Histogram::FactoryTimeGet( \
74 name, min, max, bucket_count, Histogram::kNoFlags); \ 74 name, min, max, bucket_count, Histogram::kNoFlags); \
75 DCHECK_EQ(name, counter->histogram_name()); \ 75 DCHECK_EQ(name, counter->histogram_name()); \
76 counter->AddTime(sample); \ 76 if (counter.get()) counter->AddTime(sample); \
77 } while (0) 77 } while (0)
78 78
79 // DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES. 79 // DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES.
80 #define HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \ 80 #define HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \
81 static scoped_refptr<Histogram> counter = Histogram::FactoryTimeGet( \ 81 static scoped_refptr<Histogram> counter = Histogram::FactoryTimeGet( \
82 name, min, max, bucket_count, Histogram::kNoFlags); \ 82 name, min, max, bucket_count, Histogram::kNoFlags); \
83 DCHECK_EQ(name, counter->histogram_name()); \ 83 DCHECK_EQ(name, counter->histogram_name()); \
84 if ((sample) < (max)) counter->AddTime(sample); \ 84 if ((sample) < (max) && counter.get()) counter->AddTime(sample); \
85 } while (0) 85 } while (0)
86 86
87 // Support histograming of an enumerated value. The samples should always be 87 // Support histograming of an enumerated value. The samples should always be
88 // less than boundary_value. 88 // less than boundary_value.
89 89
90 #define HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ 90 #define HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \
91 static scoped_refptr<Histogram> counter = LinearHistogram::FactoryGet( \ 91 static scoped_refptr<Histogram> counter = LinearHistogram::FactoryGet( \
92 name, 1, boundary_value, boundary_value + 1, Histogram::kNoFlags); \ 92 name, 1, boundary_value, boundary_value + 1, Histogram::kNoFlags); \
93 DCHECK_EQ(name, counter->histogram_name()); \ 93 DCHECK_EQ(name, counter->histogram_name()); \
94 counter->Add(sample); \ 94 if (counter.get()) counter->Add(sample); \
95 } while (0) 95 } while (0)
96 96
97 #define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ 97 #define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \
98 static scoped_refptr<Histogram> counter = CustomHistogram::FactoryGet( \ 98 static scoped_refptr<Histogram> counter = CustomHistogram::FactoryGet( \
99 name, custom_ranges, Histogram::kNoFlags); \ 99 name, custom_ranges, Histogram::kNoFlags); \
100 DCHECK_EQ(name, counter->histogram_name()); \ 100 DCHECK_EQ(name, counter->histogram_name()); \
101 counter->Add(sample); \ 101 if (counter.get()) counter->Add(sample); \
102 } while (0) 102 } while (0)
103 103
104 104
105 //------------------------------------------------------------------------------ 105 //------------------------------------------------------------------------------
106 // Define Debug vs non-debug flavors of macros. 106 // Define Debug vs non-debug flavors of macros.
107 #ifndef NDEBUG 107 #ifndef NDEBUG
108 108
109 #define DHISTOGRAM_TIMES(name, sample) HISTOGRAM_TIMES(name, sample) 109 #define DHISTOGRAM_TIMES(name, sample) HISTOGRAM_TIMES(name, sample)
110 #define DHISTOGRAM_COUNTS(name, sample) HISTOGRAM_COUNTS(name, sample) 110 #define DHISTOGRAM_COUNTS(name, sample) HISTOGRAM_COUNTS(name, sample)
111 #define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) HISTOGRAM_PERCENTAGE(\ 111 #define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) HISTOGRAM_PERCENTAGE(\
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 // Use this macro when times can routinely be much longer than 10 seconds. 155 // Use this macro when times can routinely be much longer than 10 seconds.
156 #define UMA_HISTOGRAM_LONG_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \ 156 #define UMA_HISTOGRAM_LONG_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \
157 name, sample, base::TimeDelta::FromMilliseconds(1), \ 157 name, sample, base::TimeDelta::FromMilliseconds(1), \
158 base::TimeDelta::FromHours(1), 50) 158 base::TimeDelta::FromHours(1), 50)
159 159
160 #define UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \ 160 #define UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \
161 static scoped_refptr<Histogram> counter = Histogram::FactoryTimeGet( \ 161 static scoped_refptr<Histogram> counter = Histogram::FactoryTimeGet( \
162 name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \ 162 name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \
163 DCHECK_EQ(name, counter->histogram_name()); \ 163 DCHECK_EQ(name, counter->histogram_name()); \
164 counter->AddTime(sample); \ 164 if (counter.get()) counter->AddTime(sample); \
165 } while (0) 165 } while (0)
166 166
167 // DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES. 167 // DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES.
168 #define UMA_HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \ 168 #define UMA_HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \
169 static scoped_refptr<Histogram> counter = Histogram::FactoryTimeGet( \ 169 static scoped_refptr<Histogram> counter = Histogram::FactoryTimeGet( \
170 name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \ 170 name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \
171 DCHECK_EQ(name, counter->histogram_name()); \ 171 DCHECK_EQ(name, counter->histogram_name()); \
172 if ((sample) < (max)) counter->AddTime(sample); \ 172 if ((sample) < (max) && counter.get()) counter->AddTime(sample); \
173 } while (0) 173 } while (0)
174 174
175 #define UMA_HISTOGRAM_COUNTS(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ 175 #define UMA_HISTOGRAM_COUNTS(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
176 name, sample, 1, 1000000, 50) 176 name, sample, 1, 1000000, 50)
177 177
178 #define UMA_HISTOGRAM_COUNTS_100(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ 178 #define UMA_HISTOGRAM_COUNTS_100(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
179 name, sample, 1, 100, 50) 179 name, sample, 1, 100, 50)
180 180
181 #define UMA_HISTOGRAM_COUNTS_10000(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ 181 #define UMA_HISTOGRAM_COUNTS_10000(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
182 name, sample, 1, 10000, 50) 182 name, sample, 1, 10000, 50)
183 183
184 #define UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \ 184 #define UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \
185 static scoped_refptr<Histogram> counter = Histogram::FactoryGet( \ 185 static scoped_refptr<Histogram> counter = Histogram::FactoryGet( \
186 name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \ 186 name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \
187 DCHECK_EQ(name, counter->histogram_name()); \ 187 DCHECK_EQ(name, counter->histogram_name()); \
188 counter->Add(sample); \ 188 if (counter.get()) counter->Add(sample); \
189 } while (0) 189 } while (0)
190 190
191 #define UMA_HISTOGRAM_MEMORY_KB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ 191 #define UMA_HISTOGRAM_MEMORY_KB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
192 name, sample, 1000, 500000, 50) 192 name, sample, 1000, 500000, 50)
193 193
194 #define UMA_HISTOGRAM_MEMORY_MB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ 194 #define UMA_HISTOGRAM_MEMORY_MB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
195 name, sample, 1, 1000, 50) 195 name, sample, 1, 1000, 50)
196 196
197 #define UMA_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ 197 #define UMA_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \
198 UMA_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) 198 UMA_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101)
199 199
200 #define UMA_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ 200 #define UMA_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \
201 static scoped_refptr<Histogram> counter = LinearHistogram::FactoryGet( \ 201 static scoped_refptr<Histogram> counter = LinearHistogram::FactoryGet( \
202 name, 1, boundary_value, boundary_value + 1, \ 202 name, 1, boundary_value, boundary_value + 1, \
203 Histogram::kUmaTargetedHistogramFlag); \ 203 Histogram::kUmaTargetedHistogramFlag); \
204 DCHECK_EQ(name, counter->histogram_name()); \ 204 DCHECK_EQ(name, counter->histogram_name()); \
205 counter->Add(sample); \ 205 if (counter.get()) counter->Add(sample); \
206 } while (0) 206 } while (0)
207 207
208 #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ 208 #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \
209 static scoped_refptr<Histogram> counter = CustomHistogram::FactoryGet( \ 209 static scoped_refptr<Histogram> counter = CustomHistogram::FactoryGet( \
210 name, custom_ranges, Histogram::kUmaTargetedHistogramFlag); \ 210 name, custom_ranges, Histogram::kUmaTargetedHistogramFlag); \
211 DCHECK_EQ(name, counter->histogram_name()); \ 211 DCHECK_EQ(name, counter->histogram_name()); \
212 counter->Add(sample); \ 212 if (counter.get()) counter->Add(sample); \
213 } while (0) 213 } while (0)
214 214
215 //------------------------------------------------------------------------------ 215 //------------------------------------------------------------------------------
216 216
217 class BooleanHistogram; 217 class BooleanHistogram;
218 class CustomHistogram; 218 class CustomHistogram;
219 class Histogram; 219 class Histogram;
220 class LinearHistogram; 220 class LinearHistogram;
221 class Pickle; 221 class Pickle;
222 222
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 // lock protects access to the above map. 627 // lock protects access to the above map.
628 static Lock* lock_; 628 static Lock* lock_;
629 629
630 // Dump all known histograms to log. 630 // Dump all known histograms to log.
631 static bool dump_on_exit_; 631 static bool dump_on_exit_;
632 632
633 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); 633 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder);
634 }; 634 };
635 635
636 #endif // BASE_HISTOGRAM_H_ 636 #endif // BASE_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698