blob: a44a2eb8888a517eef35f134737def5d9f46d760 [file] [log] [blame]
[email protected]0704a972011-03-24 00:30:271// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
5// Histogram is an object that aggregates statistics, and can summarize them in
6// various forms, including ASCII graphical, HTML, and numerically (as a
7// vector of numbers corresponding to each of the aggregating buckets).
8// See header file for details and examples.
9
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
initial.commitd7cae122008-07-26 21:49:3811
12#include <math.h>
[email protected]f1633932010-08-17 23:05:2813
14#include <algorithm>
initial.commitd7cae122008-07-26 21:49:3815#include <string>
16
[email protected]9b3bbd62011-05-31 07:37:0917#include "base/debug/leak_annotations.h"
initial.commitd7cae122008-07-26 21:49:3818#include "base/logging.h"
[email protected]3f383852009-04-03 18:18:5519#include "base/pickle.h"
[email protected]f1633932010-08-17 23:05:2820#include "base/stringprintf.h"
[email protected]bc581a682011-01-01 23:16:2021#include "base/synchronization/lock.h"
initial.commitd7cae122008-07-26 21:49:3822
[email protected]835d7c82010-10-14 04:38:3823namespace base {
[email protected]e1acf6f2008-10-27 20:43:3324
[email protected]98359ce2011-03-05 06:22:2425// Static table of checksums for all possible 8 bit bytes.
26const uint32 Histogram::kCrcTable[256] = {0x0, 0x77073096L, 0xee0e612cL,
270x990951baL, 0x76dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0xedb8832L,
280x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x9b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
290x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x1adad47dL,
300x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, 0x646ba8c0L, 0xfd62f97aL,
310x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L,
320x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL,
330xa50ab56bL, 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
340x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, 0xc8d75180L,
350xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL, 0x2802b89eL,
360x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL,
370xb6662d3dL, 0x76dc4190L, 0x1db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L,
380x6b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0xf00f934L, 0x9609a88eL,
390xe10e9818L, 0x7f6a0dbbL, 0x86d3d2dL, 0x91646c97L, 0xe6635c01L, 0x6b6b51f4L,
400x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L,
410xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL,
420x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L,
430xd4bb30e2L, 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
440x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL,
450xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L, 0x5768b525L,
460x206f85b3L, 0xb966d409L, 0xce61e49fL, 0x5edef90eL, 0x29d9c998L, 0xb0d09822L,
470xc7d7a8b4L, 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L,
480x9abfb3b6L, 0x3b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x4db2615L,
490x73dc1683L, 0xe3630b12L, 0x94643b84L, 0xd6d6a3eL, 0x7a6a5aa8L, 0xe40ecf0bL,
500x9309ff9dL, 0xa00ae27L, 0x7d079eb1L, 0xf00f9344L, 0x8708a3d2L, 0x1e01f268L,
510x6906c2feL, 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L,
520x89d32be0L, 0x10da7a5aL, 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L,
530x60b08ed5L, 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
540xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L,
550x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L, 0xcb61b38cL,
560xbc66831aL, 0x256fd2a0L, 0x5268e236L, 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L,
570x5505262fL, 0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L,
580xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
590x26d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x5005713L, 0x95bf4a82L,
600xe2b87a14L, 0x7bb12baeL, 0xcb61b38L, 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L,
610xbdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL,
620xf6b9265bL, 0x6fb077e1L, 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL,
630x11010b5cL, 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
640xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 0x4969474dL,
650x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L, 0xa9bcae53L,
660xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L,
670x24b4a3a6L, 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL,
680xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
690x2d02ef8dL,
70};
71
initial.commitd7cae122008-07-26 21:49:3872typedef Histogram::Count Count;
73
[email protected]b122c0c2011-02-23 22:31:1874// static
[email protected]9fce5f02011-03-02 08:04:5775const size_t Histogram::kBucketCount_MAX = 16384u;
[email protected]b122c0c2011-02-23 22:31:1876
[email protected]908de522011-10-20 00:55:0077// Collect the number of histograms created.
78static uint32 number_of_histograms_ = 0;
79// Collect the number of vectors saved because of caching ranges.
80static uint32 number_of_vectors_saved_ = 0;
81// Collect the number of ranges_ elements saved because of caching ranges.
82static size_t saved_ranges_size_ = 0;
83
[email protected]81ce9f3b2011-04-05 04:48:5384Histogram* Histogram::FactoryGet(const std::string& name,
85 Sample minimum,
86 Sample maximum,
87 size_t bucket_count,
88 Flags flags) {
89 Histogram* histogram(NULL);
[email protected]e8829a192009-12-06 00:09:3790
91 // Defensive code.
[email protected]2ef3748f2010-10-19 17:33:2892 if (minimum < 1)
[email protected]e8829a192009-12-06 00:09:3793 minimum = 1;
[email protected]2ef3748f2010-10-19 17:33:2894 if (maximum > kSampleType_MAX - 1)
[email protected]e8829a192009-12-06 00:09:3795 maximum = kSampleType_MAX - 1;
96
[email protected]f2bc0cb52010-06-25 15:55:1597 if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
[email protected]81ce9f3b2011-04-05 04:48:5398 // Extra variable is not needed... but this keeps this section basically
99 // identical to other derived classes in this file (and compiler will
100 // optimize away the extra variable.
101 // To avoid racy destruction at shutdown, the following will be leaked.
102 Histogram* tentative_histogram =
103 new Histogram(name, minimum, maximum, bucket_count);
104 tentative_histogram->InitializeBucketRange();
105 tentative_histogram->SetFlags(flags);
106 histogram =
107 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
[email protected]e8829a192009-12-06 00:09:37108 }
109
[email protected]2ef3748f2010-10-19 17:33:28110 DCHECK_EQ(HISTOGRAM, histogram->histogram_type());
[email protected]e8829a192009-12-06 00:09:37111 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
[email protected]e8829a192009-12-06 00:09:37112 return histogram;
113}
114
[email protected]81ce9f3b2011-04-05 04:48:53115Histogram* Histogram::FactoryTimeGet(const std::string& name,
116 TimeDelta minimum,
117 TimeDelta maximum,
118 size_t bucket_count,
119 Flags flags) {
[email protected]2753b392009-12-28 06:59:52120 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(),
121 bucket_count, flags);
[email protected]e8829a192009-12-06 00:09:37122}
123
[email protected]b404b1f2011-10-16 07:29:17124TimeTicks Histogram::DebugNow() {
125#ifndef NDEBUG
126 return TimeTicks::Now();
127#else
128 return TimeTicks();
129#endif
130}
131
initial.commitd7cae122008-07-26 21:49:38132void Histogram::Add(int value) {
[email protected]2ef3748f2010-10-19 17:33:28133 if (value > kSampleType_MAX - 1)
initial.commitd7cae122008-07-26 21:49:38134 value = kSampleType_MAX - 1;
initial.commitd7cae122008-07-26 21:49:38135 if (value < 0)
136 value = 0;
137 size_t index = BucketIndex(value);
[email protected]2ef3748f2010-10-19 17:33:28138 DCHECK_GE(value, ranges(index));
139 DCHECK_LT(value, ranges(index + 1));
initial.commitd7cae122008-07-26 21:49:38140 Accumulate(value, 1, index);
141}
142
[email protected]5d91c9e2010-07-28 17:25:28143void Histogram::AddBoolean(bool value) {
144 DCHECK(false);
145}
146
[email protected]55e57d42009-02-25 06:10:17147void Histogram::AddSampleSet(const SampleSet& sample) {
148 sample_.Add(sample);
149}
150
[email protected]5d91c9e2010-07-28 17:25:28151void Histogram::SetRangeDescriptions(const DescriptionPair descriptions[]) {
152 DCHECK(false);
153}
154
initial.commitd7cae122008-07-26 21:49:38155// The following methods provide a graphical histogram display.
156void Histogram::WriteHTMLGraph(std::string* output) const {
157 // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc.
158 output->append("<PRE>");
159 WriteAscii(true, "<br>", output);
160 output->append("</PRE>");
161}
162
163void Histogram::WriteAscii(bool graph_it, const std::string& newline,
164 std::string* output) const {
165 // Get local (stack) copies of all effectively volatile class data so that we
166 // are consistent across our output activities.
167 SampleSet snapshot;
168 SnapshotSample(&snapshot);
169 Count sample_count = snapshot.TotalCount();
170
171 WriteAsciiHeader(snapshot, sample_count, output);
172 output->append(newline);
173
174 // Prepare to normalize graphical rendering of bucket contents.
175 double max_size = 0;
176 if (graph_it)
177 max_size = GetPeakBucketSize(snapshot);
178
179 // Calculate space needed to print bucket range numbers. Leave room to print
180 // nearly the largest bucket range without sliding over the histogram.
[email protected]e2951cf2008-09-24 23:51:25181 size_t largest_non_empty_bucket = bucket_count() - 1;
182 while (0 == snapshot.counts(largest_non_empty_bucket)) {
initial.commitd7cae122008-07-26 21:49:38183 if (0 == largest_non_empty_bucket)
184 break; // All buckets are empty.
[email protected]55e57d42009-02-25 06:10:17185 --largest_non_empty_bucket;
initial.commitd7cae122008-07-26 21:49:38186 }
187
188 // Calculate largest print width needed for any of our bucket range displays.
189 size_t print_width = 1;
[email protected]e2951cf2008-09-24 23:51:25190 for (size_t i = 0; i < bucket_count(); ++i) {
initial.commitd7cae122008-07-26 21:49:38191 if (snapshot.counts(i)) {
192 size_t width = GetAsciiBucketRange(i).size() + 1;
193 if (width > print_width)
194 print_width = width;
195 }
196 }
197
198 int64 remaining = sample_count;
199 int64 past = 0;
200 // Output the actual histogram graph.
[email protected]55e57d42009-02-25 06:10:17201 for (size_t i = 0; i < bucket_count(); ++i) {
initial.commitd7cae122008-07-26 21:49:38202 Count current = snapshot.counts(i);
203 if (!current && !PrintEmptyBucket(i))
204 continue;
205 remaining -= current;
[email protected]34b2b002009-11-20 06:53:28206 std::string range = GetAsciiBucketRange(i);
207 output->append(range);
208 for (size_t j = 0; range.size() + j < print_width + 1; ++j)
209 output->push_back(' ');
[email protected]e2951cf2008-09-24 23:51:25210 if (0 == current && i < bucket_count() - 1 && 0 == snapshot.counts(i + 1)) {
211 while (i < bucket_count() - 1 && 0 == snapshot.counts(i + 1))
[email protected]55e57d42009-02-25 06:10:17212 ++i;
initial.commitd7cae122008-07-26 21:49:38213 output->append("... ");
214 output->append(newline);
215 continue; // No reason to plot emptiness.
216 }
217 double current_size = GetBucketSize(current, i);
218 if (graph_it)
219 WriteAsciiBucketGraph(current_size, max_size, output);
220 WriteAsciiBucketContext(past, current, remaining, i, output);
221 output->append(newline);
222 past += current;
223 }
[email protected]2ef3748f2010-10-19 17:33:28224 DCHECK_EQ(sample_count, past);
initial.commitd7cae122008-07-26 21:49:38225}
226
[email protected]55e57d42009-02-25 06:10:17227// static
228std::string Histogram::SerializeHistogramInfo(const Histogram& histogram,
229 const SampleSet& snapshot) {
[email protected]2ef3748f2010-10-19 17:33:28230 DCHECK_NE(NOT_VALID_IN_RENDERER, histogram.histogram_type());
[email protected]55e57d42009-02-25 06:10:17231
[email protected]e8829a192009-12-06 00:09:37232 Pickle pickle;
[email protected]55e57d42009-02-25 06:10:17233 pickle.WriteString(histogram.histogram_name());
234 pickle.WriteInt(histogram.declared_min());
235 pickle.WriteInt(histogram.declared_max());
236 pickle.WriteSize(histogram.bucket_count());
[email protected]98359ce2011-03-05 06:22:24237 pickle.WriteUInt32(histogram.range_checksum());
[email protected]55e57d42009-02-25 06:10:17238 pickle.WriteInt(histogram.histogram_type());
[email protected]1f4fc8e8c2010-01-02 00:46:41239 pickle.WriteInt(histogram.flags());
[email protected]55e57d42009-02-25 06:10:17240
241 snapshot.Serialize(&pickle);
[email protected]cd56dff2011-11-13 04:19:15242
243 histogram.SerializeRanges(&pickle);
244
[email protected]55e57d42009-02-25 06:10:17245 return std::string(static_cast<const char*>(pickle.data()), pickle.size());
246}
247
248// static
[email protected]55e57d42009-02-25 06:10:17249bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) {
250 if (histogram_info.empty()) {
[email protected]cd56dff2011-11-13 04:19:15251 return false;
[email protected]55e57d42009-02-25 06:10:17252 }
253
254 Pickle pickle(histogram_info.data(),
255 static_cast<int>(histogram_info.size()));
[email protected]93a41d72010-11-03 23:36:24256 std::string histogram_name;
[email protected]55e57d42009-02-25 06:10:17257 int declared_min;
258 int declared_max;
[email protected]93a41d72010-11-03 23:36:24259 size_t bucket_count;
[email protected]98359ce2011-03-05 06:22:24260 uint32 range_checksum;
[email protected]55e57d42009-02-25 06:10:17261 int histogram_type;
[email protected]2753b392009-12-28 06:59:52262 int pickle_flags;
[email protected]55e57d42009-02-25 06:10:17263 SampleSet sample;
264
[email protected]93a41d72010-11-03 23:36:24265 void* iter = NULL;
[email protected]55e57d42009-02-25 06:10:17266 if (!pickle.ReadString(&iter, &histogram_name) ||
267 !pickle.ReadInt(&iter, &declared_min) ||
268 !pickle.ReadInt(&iter, &declared_max) ||
269 !pickle.ReadSize(&iter, &bucket_count) ||
[email protected]98359ce2011-03-05 06:22:24270 !pickle.ReadUInt32(&iter, &range_checksum) ||
[email protected]55e57d42009-02-25 06:10:17271 !pickle.ReadInt(&iter, &histogram_type) ||
[email protected]2753b392009-12-28 06:59:52272 !pickle.ReadInt(&iter, &pickle_flags) ||
[email protected]55e57d42009-02-25 06:10:17273 !sample.Histogram::SampleSet::Deserialize(&iter, pickle)) {
[email protected]a42d4632011-10-26 21:48:00274 DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name;
[email protected]55e57d42009-02-25 06:10:17275 return false;
276 }
[email protected]cd56dff2011-11-13 04:19:15277
[email protected]1f4fc8e8c2010-01-02 00:46:41278 DCHECK(pickle_flags & kIPCSerializationSourceFlag);
[email protected]86440f52009-12-31 05:17:23279 // Since these fields may have come from an untrusted renderer, do additional
280 // checks above and beyond those in Histogram::Initialize()
281 if (declared_max <= 0 || declared_min <= 0 || declared_max < declared_min ||
282 INT_MAX / sizeof(Count) <= bucket_count || bucket_count < 2) {
[email protected]a42d4632011-10-26 21:48:00283 DLOG(ERROR) << "Values error decoding Histogram: " << histogram_name;
[email protected]86440f52009-12-31 05:17:23284 return false;
285 }
286
[email protected]2753b392009-12-28 06:59:52287 Flags flags = static_cast<Flags>(pickle_flags & ~kIPCSerializationSourceFlag);
[email protected]55e57d42009-02-25 06:10:17288
[email protected]2ef3748f2010-10-19 17:33:28289 DCHECK_NE(NOT_VALID_IN_RENDERER, histogram_type);
[email protected]55e57d42009-02-25 06:10:17290
[email protected]81ce9f3b2011-04-05 04:48:53291 Histogram* render_histogram(NULL);
[email protected]e8829a192009-12-06 00:09:37292
[email protected]a764bf5e2010-06-02 21:31:44293 if (histogram_type == HISTOGRAM) {
[email protected]2753b392009-12-28 06:59:52294 render_histogram = Histogram::FactoryGet(
295 histogram_name, declared_min, declared_max, bucket_count, flags);
[email protected]e8829a192009-12-06 00:09:37296 } else if (histogram_type == LINEAR_HISTOGRAM) {
[email protected]2753b392009-12-28 06:59:52297 render_histogram = LinearHistogram::FactoryGet(
298 histogram_name, declared_min, declared_max, bucket_count, flags);
[email protected]e8829a192009-12-06 00:09:37299 } else if (histogram_type == BOOLEAN_HISTOGRAM) {
[email protected]2753b392009-12-28 06:59:52300 render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags);
[email protected]cd56dff2011-11-13 04:19:15301 } else if (histogram_type == CUSTOM_HISTOGRAM) {
302 std::vector<Histogram::Sample> sample_ranges(bucket_count);
303 if (!CustomHistogram::DeserializeRanges(&iter, pickle, &sample_ranges)) {
304 DLOG(ERROR) << "Pickle error decoding ranges: " << histogram_name;
305 return false;
306 }
307 render_histogram =
308 CustomHistogram::FactoryGet(histogram_name, sample_ranges, flags);
[email protected]e8829a192009-12-06 00:09:37309 } else {
[email protected]a42d4632011-10-26 21:48:00310 DLOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: "
311 << histogram_type;
[email protected]e8829a192009-12-06 00:09:37312 return false;
[email protected]55e57d42009-02-25 06:10:17313 }
314
[email protected]2ef3748f2010-10-19 17:33:28315 DCHECK_EQ(render_histogram->declared_min(), declared_min);
316 DCHECK_EQ(render_histogram->declared_max(), declared_max);
317 DCHECK_EQ(render_histogram->bucket_count(), bucket_count);
[email protected]93a41d72010-11-03 23:36:24318 DCHECK_EQ(render_histogram->range_checksum(), range_checksum);
[email protected]2ef3748f2010-10-19 17:33:28319 DCHECK_EQ(render_histogram->histogram_type(), histogram_type);
[email protected]55e57d42009-02-25 06:10:17320
[email protected]e8829a192009-12-06 00:09:37321 if (render_histogram->flags() & kIPCSerializationSourceFlag) {
[email protected]2ef3748f2010-10-19 17:33:28322 DVLOG(1) << "Single process mode, histogram observed and not copied: "
323 << histogram_name;
[email protected]e8829a192009-12-06 00:09:37324 } else {
[email protected]2ef3748f2010-10-19 17:33:28325 DCHECK_EQ(flags & render_histogram->flags(), flags);
[email protected]e8829a192009-12-06 00:09:37326 render_histogram->AddSampleSet(sample);
[email protected]55e57d42009-02-25 06:10:17327 }
328
329 return true;
330}
331
initial.commitd7cae122008-07-26 21:49:38332//------------------------------------------------------------------------------
[email protected]93a41d72010-11-03 23:36:24333// Methods for the validating a sample and a related histogram.
334//------------------------------------------------------------------------------
335
336Histogram::Inconsistencies Histogram::FindCorruption(
337 const SampleSet& snapshot) const {
338 int inconsistencies = NO_INCONSISTENCIES;
339 Sample previous_range = -1; // Bottom range is always 0.
[email protected]93a41d72010-11-03 23:36:24340 int64 count = 0;
341 for (size_t index = 0; index < bucket_count(); ++index) {
342 count += snapshot.counts(index);
343 int new_range = ranges(index);
[email protected]93a41d72010-11-03 23:36:24344 if (previous_range >= new_range)
345 inconsistencies |= BUCKET_ORDER_ERROR;
346 previous_range = new_range;
347 }
348
[email protected]98359ce2011-03-05 06:22:24349 if (!HasValidRangeChecksum())
[email protected]93a41d72010-11-03 23:36:24350 inconsistencies |= RANGE_CHECKSUM_ERROR;
351
352 int64 delta64 = snapshot.redundant_count() - count;
353 if (delta64 != 0) {
354 int delta = static_cast<int>(delta64);
355 if (delta != delta64)
356 delta = INT_MAX; // Flag all giant errors as INT_MAX.
357 // Since snapshots of histograms are taken asynchronously relative to
358 // sampling (and snapped from different threads), it is pretty likely that
359 // we'll catch a redundant count that doesn't match the sample count. We
360 // allow for a certain amount of slop before flagging this as an
361 // inconsistency. Even with an inconsistency, we'll snapshot it again (for
362 // UMA in about a half hour, so we'll eventually get the data, if it was
363 // not the result of a corruption. If histograms show that 1 is "too tight"
364 // then we may try to use 2 or 3 for this slop value.
365 const int kCommonRaceBasedCountMismatch = 1;
366 if (delta > 0) {
367 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentCountHigh", delta);
368 if (delta > kCommonRaceBasedCountMismatch)
369 inconsistencies |= COUNT_HIGH_ERROR;
370 } else {
371 DCHECK_GT(0, delta);
372 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentCountLow", -delta);
373 if (-delta > kCommonRaceBasedCountMismatch)
374 inconsistencies |= COUNT_LOW_ERROR;
375 }
376 }
377 return static_cast<Inconsistencies>(inconsistencies);
378}
379
[email protected]7cf40912010-12-09 18:25:03380Histogram::ClassType Histogram::histogram_type() const {
381 return HISTOGRAM;
382}
383
384Histogram::Sample Histogram::ranges(size_t i) const {
[email protected]908de522011-10-20 00:55:00385 return cached_ranges_->ranges(i);
[email protected]7cf40912010-12-09 18:25:03386}
387
388size_t Histogram::bucket_count() const {
389 return bucket_count_;
390}
391
[email protected]b7d08202011-01-25 17:29:39392// Do a safe atomic snapshot of sample data.
393// This implementation assumes we are on a safe single thread.
394void Histogram::SnapshotSample(SampleSet* sample) const {
395 // Note locking not done in this version!!!
396 *sample = sample_;
397}
398
399bool Histogram::HasConstructorArguments(Sample minimum,
400 Sample maximum,
401 size_t bucket_count) {
402 return ((minimum == declared_min_) && (maximum == declared_max_) &&
403 (bucket_count == bucket_count_));
404}
405
406bool Histogram::HasConstructorTimeDeltaArguments(TimeDelta minimum,
407 TimeDelta maximum,
408 size_t bucket_count) {
409 return ((minimum.InMilliseconds() == declared_min_) &&
410 (maximum.InMilliseconds() == declared_max_) &&
411 (bucket_count == bucket_count_));
412}
413
[email protected]98359ce2011-03-05 06:22:24414bool Histogram::HasValidRangeChecksum() const {
415 return CalculateRangeChecksum() == range_checksum_;
416}
417
[email protected]b7d08202011-01-25 17:29:39418Histogram::Histogram(const std::string& name, Sample minimum,
419 Sample maximum, size_t bucket_count)
420 : histogram_name_(name),
421 declared_min_(minimum),
422 declared_max_(maximum),
423 bucket_count_(bucket_count),
424 flags_(kNoFlags),
[email protected]908de522011-10-20 00:55:00425 cached_ranges_(new CachedRanges(bucket_count + 1, 0)),
[email protected]b7d08202011-01-25 17:29:39426 range_checksum_(0),
427 sample_() {
428 Initialize();
429}
430
431Histogram::Histogram(const std::string& name, TimeDelta minimum,
432 TimeDelta maximum, size_t bucket_count)
433 : histogram_name_(name),
434 declared_min_(static_cast<int> (minimum.InMilliseconds())),
435 declared_max_(static_cast<int> (maximum.InMilliseconds())),
436 bucket_count_(bucket_count),
437 flags_(kNoFlags),
[email protected]908de522011-10-20 00:55:00438 cached_ranges_(new CachedRanges(bucket_count + 1, 0)),
[email protected]b7d08202011-01-25 17:29:39439 range_checksum_(0),
440 sample_() {
441 Initialize();
442}
443
444Histogram::~Histogram() {
445 if (StatisticsRecorder::dump_on_exit()) {
446 std::string output;
447 WriteAscii(true, "\n", &output);
[email protected]a42d4632011-10-26 21:48:00448 DLOG(INFO) << output;
[email protected]b7d08202011-01-25 17:29:39449 }
450
451 // Just to make sure most derived class did this properly...
452 DCHECK(ValidateBucketRanges());
[email protected]7767bdb2011-03-02 23:38:00453}
454
[email protected]cd56dff2011-11-13 04:19:15455bool Histogram::SerializeRanges(Pickle* pickle) const {
456 return true;
457}
458
[email protected]b7d08202011-01-25 17:29:39459// Calculate what range of values are held in each bucket.
460// We have to be careful that we don't pick a ratio between starting points in
461// consecutive buckets that is sooo small, that the integer bounds are the same
462// (effectively making one bucket get no values). We need to avoid:
[email protected]908de522011-10-20 00:55:00463// ranges(i) == ranges(i + 1)
[email protected]b7d08202011-01-25 17:29:39464// To avoid that, we just do a fine-grained bucket width as far as we need to
465// until we get a ratio that moves us along at least 2 units at a time. From
466// that bucket onward we do use the exponential growth of buckets.
467void Histogram::InitializeBucketRange() {
468 double log_max = log(static_cast<double>(declared_max()));
469 double log_ratio;
470 double log_next;
471 size_t bucket_index = 1;
472 Sample current = declared_min();
473 SetBucketRange(bucket_index, current);
474 while (bucket_count() > ++bucket_index) {
475 double log_current;
476 log_current = log(static_cast<double>(current));
477 // Calculate the count'th root of the range.
478 log_ratio = (log_max - log_current) / (bucket_count() - bucket_index);
479 // See where the next bucket would start.
480 log_next = log_current + log_ratio;
481 int next;
482 next = static_cast<int>(floor(exp(log_next) + 0.5));
483 if (next > current)
484 current = next;
485 else
486 ++current; // Just do a narrow bucket, and keep trying.
487 SetBucketRange(bucket_index, current);
488 }
489 ResetRangeChecksum();
490
491 DCHECK_EQ(bucket_count(), bucket_index);
492}
493
[email protected]98359ce2011-03-05 06:22:24494bool Histogram::PrintEmptyBucket(size_t index) const {
495 return true;
496}
497
[email protected]b7d08202011-01-25 17:29:39498size_t Histogram::BucketIndex(Sample value) const {
499 // Use simple binary search. This is very general, but there are better
500 // approaches if we knew that the buckets were linearly distributed.
501 DCHECK_LE(ranges(0), value);
502 DCHECK_GT(ranges(bucket_count()), value);
503 size_t under = 0;
504 size_t over = bucket_count();
505 size_t mid;
506
507 do {
508 DCHECK_GE(over, under);
[email protected]b122c0c2011-02-23 22:31:18509 mid = under + (over - under)/2;
[email protected]b7d08202011-01-25 17:29:39510 if (mid == under)
511 break;
512 if (ranges(mid) <= value)
513 under = mid;
514 else
515 over = mid;
516 } while (true);
517
518 DCHECK_LE(ranges(mid), value);
[email protected]b122c0c2011-02-23 22:31:18519 CHECK_GT(ranges(mid+1), value);
[email protected]b7d08202011-01-25 17:29:39520 return mid;
521}
522
523// Use the actual bucket widths (like a linear histogram) until the widths get
524// over some transition value, and then use that transition width. Exponentials
525// get so big so fast (and we don't expect to see a lot of entries in the large
526// buckets), so we need this to make it possible to see what is going on and
527// not have 0-graphical-height buckets.
528double Histogram::GetBucketSize(Count current, size_t i) const {
529 DCHECK_GT(ranges(i + 1), ranges(i));
530 static const double kTransitionWidth = 5;
531 double denominator = ranges(i + 1) - ranges(i);
532 if (denominator > kTransitionWidth)
533 denominator = kTransitionWidth; // Stop trying to normalize.
534 return current/denominator;
535}
536
537void Histogram::ResetRangeChecksum() {
538 range_checksum_ = CalculateRangeChecksum();
539}
540
541const std::string Histogram::GetAsciiBucketRange(size_t i) const {
542 std::string result;
543 if (kHexRangePrintingFlag & flags_)
544 StringAppendF(&result, "%#x", ranges(i));
545 else
546 StringAppendF(&result, "%d", ranges(i));
547 return result;
548}
549
550// Update histogram data with new sample.
551void Histogram::Accumulate(Sample value, Count count, size_t index) {
552 // Note locking not done in this version!!!
553 sample_.Accumulate(value, count, index);
554}
555
556void Histogram::SetBucketRange(size_t i, Sample value) {
557 DCHECK_GT(bucket_count_, i);
[email protected]c89b2442011-05-26 14:28:27558 DCHECK_GE(value, 0);
[email protected]908de522011-10-20 00:55:00559 cached_ranges_->SetBucketRange(i, value);
[email protected]b7d08202011-01-25 17:29:39560}
561
562bool Histogram::ValidateBucketRanges() const {
563 // Standard assertions that all bucket ranges should satisfy.
[email protected]908de522011-10-20 00:55:00564 DCHECK_EQ(bucket_count_ + 1, cached_ranges_->size());
565 DCHECK_EQ(0, ranges(0));
566 DCHECK_EQ(declared_min(), ranges(1));
567 DCHECK_EQ(declared_max(), ranges(bucket_count_ - 1));
568 DCHECK_EQ(kSampleType_MAX, ranges(bucket_count_));
[email protected]b7d08202011-01-25 17:29:39569 return true;
570}
571
[email protected]98359ce2011-03-05 06:22:24572uint32 Histogram::CalculateRangeChecksum() const {
[email protected]908de522011-10-20 00:55:00573 DCHECK_EQ(cached_ranges_->size(), bucket_count() + 1);
574 // Seed checksum.
575 uint32 checksum = static_cast<uint32>(cached_ranges_->size());
[email protected]98359ce2011-03-05 06:22:24576 for (size_t index = 0; index < bucket_count(); ++index)
577 checksum = Crc32(checksum, ranges(index));
578 return checksum;
579}
580
[email protected]b7d08202011-01-25 17:29:39581void Histogram::Initialize() {
582 sample_.Resize(*this);
583 if (declared_min_ < 1)
584 declared_min_ = 1;
585 if (declared_max_ > kSampleType_MAX - 1)
586 declared_max_ = kSampleType_MAX - 1;
587 DCHECK_LE(declared_min_, declared_max_);
588 DCHECK_GT(bucket_count_, 1u);
[email protected]b122c0c2011-02-23 22:31:18589 CHECK_LT(bucket_count_, kBucketCount_MAX);
[email protected]b7d08202011-01-25 17:29:39590 size_t maximal_bucket_count = declared_max_ - declared_min_ + 2;
591 DCHECK_LE(bucket_count_, maximal_bucket_count);
[email protected]908de522011-10-20 00:55:00592 DCHECK_EQ(0, ranges(0));
593 cached_ranges_->SetBucketRange(bucket_count_, kSampleType_MAX);
[email protected]b7d08202011-01-25 17:29:39594}
595
[email protected]98359ce2011-03-05 06:22:24596// We generate the CRC-32 using the low order bits to select whether to XOR in
597// the reversed polynomial 0xedb88320L. This is nice and simple, and allows us
598// to keep the quotient in a uint32. Since we're not concerned about the nature
599// of corruptions (i.e., we don't care about bit sequencing, since we are
600// handling memory changes, which are more grotesque) so we don't bother to
601// get the CRC correct for big-endian vs little-ending calculations. All we
602// need is a nice hash, that tends to depend on all the bits of the sample, with
603// very little chance of changes in one place impacting changes in another
604// place.
605uint32 Histogram::Crc32(uint32 sum, Histogram::Sample range) {
606 const bool kUseRealCrc = true; // TODO(jar): Switch to false and watch stats.
607 if (kUseRealCrc) {
608 union {
609 Histogram::Sample range;
610 unsigned char bytes[sizeof(Histogram::Sample)];
611 } converter;
612 converter.range = range;
613 for (size_t i = 0; i < sizeof(converter); ++i)
614 sum = kCrcTable[(sum & 0xff) ^ converter.bytes[i]] ^ (sum >> 8);
615 } else {
616 // Use hash techniques provided in ReallyFastHash, except we don't care
617 // about "avalanching" (which would worsten the hash, and add collisions),
618 // and we don't care about edge cases since we have an even number of bytes.
619 union {
620 Histogram::Sample range;
621 uint16 ints[sizeof(Histogram::Sample) / 2];
622 } converter;
623 DCHECK_EQ(sizeof(Histogram::Sample), sizeof(converter));
624 converter.range = range;
625 sum += converter.ints[0];
626 sum = (sum << 16) ^ sum ^ (static_cast<uint32>(converter.ints[1]) << 11);
627 sum += sum >> 11;
[email protected]b7d08202011-01-25 17:29:39628 }
[email protected]98359ce2011-03-05 06:22:24629 return sum;
[email protected]b7d08202011-01-25 17:29:39630}
631
632//------------------------------------------------------------------------------
633// Private methods
634
635double Histogram::GetPeakBucketSize(const SampleSet& snapshot) const {
636 double max = 0;
637 for (size_t i = 0; i < bucket_count() ; ++i) {
638 double current_size = GetBucketSize(snapshot.counts(i), i);
639 if (current_size > max)
640 max = current_size;
641 }
642 return max;
643}
644
645void Histogram::WriteAsciiHeader(const SampleSet& snapshot,
646 Count sample_count,
647 std::string* output) const {
648 StringAppendF(output,
649 "Histogram: %s recorded %d samples",
650 histogram_name().c_str(),
651 sample_count);
652 if (0 == sample_count) {
653 DCHECK_EQ(snapshot.sum(), 0);
654 } else {
655 double average = static_cast<float>(snapshot.sum()) / sample_count;
[email protected]b7d08202011-01-25 17:29:39656
[email protected]0704a972011-03-24 00:30:27657 StringAppendF(output, ", average = %.1f", average);
[email protected]b7d08202011-01-25 17:29:39658 }
659 if (flags_ & ~kHexRangePrintingFlag)
660 StringAppendF(output, " (flags = 0x%x)", flags_ & ~kHexRangePrintingFlag);
661}
662
663void Histogram::WriteAsciiBucketContext(const int64 past,
664 const Count current,
665 const int64 remaining,
666 const size_t i,
667 std::string* output) const {
668 double scaled_sum = (past + current + remaining) / 100.0;
669 WriteAsciiBucketValue(current, scaled_sum, output);
670 if (0 < i) {
671 double percentage = past / scaled_sum;
672 StringAppendF(output, " {%3.1f%%}", percentage);
673 }
674}
675
676void Histogram::WriteAsciiBucketValue(Count current, double scaled_sum,
677 std::string* output) const {
678 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum);
679}
680
681void Histogram::WriteAsciiBucketGraph(double current_size, double max_size,
682 std::string* output) const {
683 const int k_line_length = 72; // Maximal horizontal width of graph.
684 int x_count = static_cast<int>(k_line_length * (current_size / max_size)
685 + 0.5);
686 int x_remainder = k_line_length - x_count;
687
688 while (0 < x_count--)
689 output->append("-");
690 output->append("O");
691 while (0 < x_remainder--)
692 output->append(" ");
693}
694
[email protected]93a41d72010-11-03 23:36:24695//------------------------------------------------------------------------------
initial.commitd7cae122008-07-26 21:49:38696// Methods for the Histogram::SampleSet class
697//------------------------------------------------------------------------------
698
699Histogram::SampleSet::SampleSet()
700 : counts_(),
701 sum_(0),
[email protected]93a41d72010-11-03 23:36:24702 redundant_count_(0) {
initial.commitd7cae122008-07-26 21:49:38703}
704
[email protected]d4799a32010-09-28 22:54:58705Histogram::SampleSet::~SampleSet() {
706}
707
initial.commitd7cae122008-07-26 21:49:38708void Histogram::SampleSet::Resize(const Histogram& histogram) {
709 counts_.resize(histogram.bucket_count(), 0);
710}
711
712void Histogram::SampleSet::CheckSize(const Histogram& histogram) const {
[email protected]2ef3748f2010-10-19 17:33:28713 DCHECK_EQ(histogram.bucket_count(), counts_.size());
initial.commitd7cae122008-07-26 21:49:38714}
715
716
717void Histogram::SampleSet::Accumulate(Sample value, Count count,
718 size_t index) {
719 DCHECK(count == 1 || count == -1);
720 counts_[index] += count;
721 sum_ += count * value;
[email protected]93a41d72010-11-03 23:36:24722 redundant_count_ += count;
[email protected]2753b392009-12-28 06:59:52723 DCHECK_GE(counts_[index], 0);
724 DCHECK_GE(sum_, 0);
[email protected]93a41d72010-11-03 23:36:24725 DCHECK_GE(redundant_count_, 0);
initial.commitd7cae122008-07-26 21:49:38726}
727
728Count Histogram::SampleSet::TotalCount() const {
729 Count total = 0;
730 for (Counts::const_iterator it = counts_.begin();
731 it != counts_.end();
[email protected]55e57d42009-02-25 06:10:17732 ++it) {
initial.commitd7cae122008-07-26 21:49:38733 total += *it;
734 }
735 return total;
736}
737
738void Histogram::SampleSet::Add(const SampleSet& other) {
[email protected]2ef3748f2010-10-19 17:33:28739 DCHECK_EQ(counts_.size(), other.counts_.size());
initial.commitd7cae122008-07-26 21:49:38740 sum_ += other.sum_;
[email protected]93a41d72010-11-03 23:36:24741 redundant_count_ += other.redundant_count_;
[email protected]55e57d42009-02-25 06:10:17742 for (size_t index = 0; index < counts_.size(); ++index)
initial.commitd7cae122008-07-26 21:49:38743 counts_[index] += other.counts_[index];
744}
745
746void Histogram::SampleSet::Subtract(const SampleSet& other) {
[email protected]2ef3748f2010-10-19 17:33:28747 DCHECK_EQ(counts_.size(), other.counts_.size());
[email protected]0704a972011-03-24 00:30:27748 // Note: Race conditions in snapshotting a sum may lead to (temporary)
749 // negative values when snapshots are later combined (and deltas calculated).
750 // As a result, we don't currently CHCEK() for positive values.
initial.commitd7cae122008-07-26 21:49:38751 sum_ -= other.sum_;
[email protected]93a41d72010-11-03 23:36:24752 redundant_count_ -= other.redundant_count_;
[email protected]55e57d42009-02-25 06:10:17753 for (size_t index = 0; index < counts_.size(); ++index) {
initial.commitd7cae122008-07-26 21:49:38754 counts_[index] -= other.counts_[index];
[email protected]2753b392009-12-28 06:59:52755 DCHECK_GE(counts_[index], 0);
initial.commitd7cae122008-07-26 21:49:38756 }
757}
758
[email protected]55e57d42009-02-25 06:10:17759bool Histogram::SampleSet::Serialize(Pickle* pickle) const {
760 pickle->WriteInt64(sum_);
[email protected]93a41d72010-11-03 23:36:24761 pickle->WriteInt64(redundant_count_);
[email protected]55e57d42009-02-25 06:10:17762 pickle->WriteSize(counts_.size());
763
764 for (size_t index = 0; index < counts_.size(); ++index) {
765 pickle->WriteInt(counts_[index]);
766 }
767
768 return true;
769}
770
771bool Histogram::SampleSet::Deserialize(void** iter, const Pickle& pickle) {
[email protected]2753b392009-12-28 06:59:52772 DCHECK_EQ(counts_.size(), 0u);
773 DCHECK_EQ(sum_, 0);
[email protected]93a41d72010-11-03 23:36:24774 DCHECK_EQ(redundant_count_, 0);
[email protected]55e57d42009-02-25 06:10:17775
776 size_t counts_size;
777
778 if (!pickle.ReadInt64(iter, &sum_) ||
[email protected]93a41d72010-11-03 23:36:24779 !pickle.ReadInt64(iter, &redundant_count_) ||
[email protected]55e57d42009-02-25 06:10:17780 !pickle.ReadSize(iter, &counts_size)) {
781 return false;
782 }
783
[email protected]86440f52009-12-31 05:17:23784 if (counts_size == 0)
[email protected]55e57d42009-02-25 06:10:17785 return false;
786
[email protected]93a41d72010-11-03 23:36:24787 int count = 0;
[email protected]55e57d42009-02-25 06:10:17788 for (size_t index = 0; index < counts_size; ++index) {
[email protected]86440f52009-12-31 05:17:23789 int i;
790 if (!pickle.ReadInt(iter, &i))
[email protected]55e57d42009-02-25 06:10:17791 return false;
[email protected]86440f52009-12-31 05:17:23792 counts_.push_back(i);
[email protected]93a41d72010-11-03 23:36:24793 count += i;
[email protected]55e57d42009-02-25 06:10:17794 }
[email protected]93a41d72010-11-03 23:36:24795 DCHECK_EQ(count, redundant_count_);
796 return count == redundant_count_;
[email protected]55e57d42009-02-25 06:10:17797}
798
initial.commitd7cae122008-07-26 21:49:38799//------------------------------------------------------------------------------
800// LinearHistogram: This histogram uses a traditional set of evenly spaced
801// buckets.
802//------------------------------------------------------------------------------
803
[email protected]b7d08202011-01-25 17:29:39804LinearHistogram::~LinearHistogram() {
805}
806
[email protected]81ce9f3b2011-04-05 04:48:53807Histogram* LinearHistogram::FactoryGet(const std::string& name,
808 Sample minimum,
809 Sample maximum,
810 size_t bucket_count,
811 Flags flags) {
812 Histogram* histogram(NULL);
[email protected]e8829a192009-12-06 00:09:37813
[email protected]2ef3748f2010-10-19 17:33:28814 if (minimum < 1)
[email protected]e8829a192009-12-06 00:09:37815 minimum = 1;
[email protected]2ef3748f2010-10-19 17:33:28816 if (maximum > kSampleType_MAX - 1)
[email protected]e8829a192009-12-06 00:09:37817 maximum = kSampleType_MAX - 1;
818
[email protected]f2bc0cb52010-06-25 15:55:15819 if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
[email protected]81ce9f3b2011-04-05 04:48:53820 // To avoid racy destruction at shutdown, the following will be leaked.
821 LinearHistogram* tentative_histogram =
[email protected]98359ce2011-03-05 06:22:24822 new LinearHistogram(name, minimum, maximum, bucket_count);
[email protected]81ce9f3b2011-04-05 04:48:53823 tentative_histogram->InitializeBucketRange();
824 tentative_histogram->SetFlags(flags);
825 histogram =
826 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
[email protected]e8829a192009-12-06 00:09:37827 }
828
[email protected]2ef3748f2010-10-19 17:33:28829 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type());
[email protected]e8829a192009-12-06 00:09:37830 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
[email protected]e8829a192009-12-06 00:09:37831 return histogram;
832}
833
[email protected]81ce9f3b2011-04-05 04:48:53834Histogram* LinearHistogram::FactoryTimeGet(const std::string& name,
835 TimeDelta minimum,
836 TimeDelta maximum,
837 size_t bucket_count,
838 Flags flags) {
[email protected]2753b392009-12-28 06:59:52839 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(),
840 bucket_count, flags);
[email protected]e8829a192009-12-06 00:09:37841}
842
[email protected]b7d08202011-01-25 17:29:39843Histogram::ClassType LinearHistogram::histogram_type() const {
844 return LINEAR_HISTOGRAM;
845}
846
847void LinearHistogram::SetRangeDescriptions(
848 const DescriptionPair descriptions[]) {
849 for (int i =0; descriptions[i].description; ++i) {
850 bucket_description_[descriptions[i].sample] = descriptions[i].description;
851 }
[email protected]d4799a32010-09-28 22:54:58852}
853
[email protected]835d7c82010-10-14 04:38:38854LinearHistogram::LinearHistogram(const std::string& name,
855 Sample minimum,
856 Sample maximum,
857 size_t bucket_count)
initial.commitd7cae122008-07-26 21:49:38858 : Histogram(name, minimum >= 1 ? minimum : 1, maximum, bucket_count) {
initial.commitd7cae122008-07-26 21:49:38859}
860
[email protected]e8829a192009-12-06 00:09:37861LinearHistogram::LinearHistogram(const std::string& name,
[email protected]835d7c82010-10-14 04:38:38862 TimeDelta minimum,
863 TimeDelta maximum,
864 size_t bucket_count)
initial.commitd7cae122008-07-26 21:49:38865 : Histogram(name, minimum >= TimeDelta::FromMilliseconds(1) ?
866 minimum : TimeDelta::FromMilliseconds(1),
867 maximum, bucket_count) {
initial.commitd7cae122008-07-26 21:49:38868}
869
initial.commitd7cae122008-07-26 21:49:38870void LinearHistogram::InitializeBucketRange() {
[email protected]70cc56e42010-04-29 22:39:55871 DCHECK_GT(declared_min(), 0); // 0 is the underflow bucket here.
initial.commitd7cae122008-07-26 21:49:38872 double min = declared_min();
873 double max = declared_max();
874 size_t i;
[email protected]55e57d42009-02-25 06:10:17875 for (i = 1; i < bucket_count(); ++i) {
initial.commitd7cae122008-07-26 21:49:38876 double linear_range = (min * (bucket_count() -1 - i) + max * (i - 1)) /
877 (bucket_count() - 2);
878 SetBucketRange(i, static_cast<int> (linear_range + 0.5));
879 }
[email protected]93a41d72010-11-03 23:36:24880 ResetRangeChecksum();
initial.commitd7cae122008-07-26 21:49:38881}
882
initial.commitd7cae122008-07-26 21:49:38883double LinearHistogram::GetBucketSize(Count current, size_t i) const {
[email protected]2ef3748f2010-10-19 17:33:28884 DCHECK_GT(ranges(i + 1), ranges(i));
initial.commitd7cae122008-07-26 21:49:38885 // Adjacent buckets with different widths would have "surprisingly" many (few)
886 // samples in a histogram if we didn't normalize this way.
887 double denominator = ranges(i + 1) - ranges(i);
888 return current/denominator;
889}
890
[email protected]b7d08202011-01-25 17:29:39891const std::string LinearHistogram::GetAsciiBucketRange(size_t i) const {
892 int range = ranges(i);
893 BucketDescriptionMap::const_iterator it = bucket_description_.find(range);
894 if (it == bucket_description_.end())
895 return Histogram::GetAsciiBucketRange(i);
896 return it->second;
897}
898
899bool LinearHistogram::PrintEmptyBucket(size_t index) const {
900 return bucket_description_.find(ranges(index)) == bucket_description_.end();
901}
902
903
initial.commitd7cae122008-07-26 21:49:38904//------------------------------------------------------------------------------
[email protected]e8829a192009-12-06 00:09:37905// This section provides implementation for BooleanHistogram.
906//------------------------------------------------------------------------------
907
[email protected]81ce9f3b2011-04-05 04:48:53908Histogram* BooleanHistogram::FactoryGet(const std::string& name, Flags flags) {
909 Histogram* histogram(NULL);
[email protected]e8829a192009-12-06 00:09:37910
[email protected]f2bc0cb52010-06-25 15:55:15911 if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
[email protected]81ce9f3b2011-04-05 04:48:53912 // To avoid racy destruction at shutdown, the following will be leaked.
913 BooleanHistogram* tentative_histogram = new BooleanHistogram(name);
914 tentative_histogram->InitializeBucketRange();
915 tentative_histogram->SetFlags(flags);
916 histogram =
917 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
[email protected]e8829a192009-12-06 00:09:37918 }
919
[email protected]2ef3748f2010-10-19 17:33:28920 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type());
[email protected]e8829a192009-12-06 00:09:37921 return histogram;
922}
923
[email protected]5d91c9e2010-07-28 17:25:28924Histogram::ClassType BooleanHistogram::histogram_type() const {
925 return BOOLEAN_HISTOGRAM;
926}
927
928void BooleanHistogram::AddBoolean(bool value) {
929 Add(value ? 1 : 0);
930}
931
932BooleanHistogram::BooleanHistogram(const std::string& name)
933 : LinearHistogram(name, 1, 2, 3) {
934}
initial.commitd7cae122008-07-26 21:49:38935
936//------------------------------------------------------------------------------
[email protected]70cc56e42010-04-29 22:39:55937// CustomHistogram:
938//------------------------------------------------------------------------------
939
[email protected]81ce9f3b2011-04-05 04:48:53940Histogram* CustomHistogram::FactoryGet(const std::string& name,
941 const std::vector<Sample>& custom_ranges,
942 Flags flags) {
943 Histogram* histogram(NULL);
[email protected]70cc56e42010-04-29 22:39:55944
945 // Remove the duplicates in the custom ranges array.
946 std::vector<int> ranges = custom_ranges;
947 ranges.push_back(0); // Ensure we have a zero value.
948 std::sort(ranges.begin(), ranges.end());
949 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end());
950 if (ranges.size() <= 1) {
951 DCHECK(false);
952 // Note that we pushed a 0 in above, so for defensive code....
953 ranges.push_back(1); // Put in some data so we can index to [1].
954 }
955
956 DCHECK_LT(ranges.back(), kSampleType_MAX);
957
[email protected]f2bc0cb52010-06-25 15:55:15958 if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
[email protected]81ce9f3b2011-04-05 04:48:53959 // To avoid racy destruction at shutdown, the following will be leaked.
960 CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges);
961 tentative_histogram->InitializedCustomBucketRange(ranges);
962 tentative_histogram->SetFlags(flags);
963 histogram =
964 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
[email protected]70cc56e42010-04-29 22:39:55965 }
966
967 DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM);
968 DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(),
969 ranges.size()));
[email protected]70cc56e42010-04-29 22:39:55970 return histogram;
971}
972
[email protected]5d91c9e2010-07-28 17:25:28973Histogram::ClassType CustomHistogram::histogram_type() const {
974 return CUSTOM_HISTOGRAM;
975}
976
[email protected]961fefb2011-05-24 13:59:58977// static
978std::vector<Histogram::Sample> CustomHistogram::ArrayToCustomRanges(
979 const Sample* values, size_t num_values) {
980 std::vector<Sample> all_values;
981 for (size_t i = 0; i < num_values; ++i) {
982 Sample value = values[i];
983 all_values.push_back(value);
984
985 // Ensure that a guard bucket is added. If we end up with duplicate
986 // values, FactoryGet will take care of removing them.
987 all_values.push_back(value + 1);
988 }
989 return all_values;
990}
991
[email protected]70cc56e42010-04-29 22:39:55992CustomHistogram::CustomHistogram(const std::string& name,
[email protected]93a41d72010-11-03 23:36:24993 const std::vector<Sample>& custom_ranges)
[email protected]70cc56e42010-04-29 22:39:55994 : Histogram(name, custom_ranges[1], custom_ranges.back(),
995 custom_ranges.size()) {
996 DCHECK_GT(custom_ranges.size(), 1u);
997 DCHECK_EQ(custom_ranges[0], 0);
[email protected]70cc56e42010-04-29 22:39:55998}
999
[email protected]cd56dff2011-11-13 04:19:151000bool CustomHistogram::SerializeRanges(Pickle* pickle) const {
1001 for (size_t i = 0; i < cached_ranges()->size(); ++i) {
1002 if (!pickle->WriteInt(cached_ranges()->ranges(i)))
1003 return false;
1004 }
1005 return true;
1006}
1007
1008// static
1009bool CustomHistogram::DeserializeRanges(
1010 void** iter, const Pickle& pickle, std::vector<Histogram::Sample>* ranges) {
1011 for (size_t i = 0; i < ranges->size(); ++i) {
1012 if (!pickle.ReadInt(iter, &(*ranges)[i]))
1013 return false;
1014 }
1015 return true;
1016}
1017
[email protected]98359ce2011-03-05 06:22:241018void CustomHistogram::InitializedCustomBucketRange(
1019 const std::vector<Sample>& custom_ranges) {
1020 DCHECK_GT(custom_ranges.size(), 1u);
1021 DCHECK_EQ(custom_ranges[0], 0);
1022 DCHECK_LE(custom_ranges.size(), bucket_count());
1023 for (size_t index = 0; index < custom_ranges.size(); ++index)
1024 SetBucketRange(index, custom_ranges[index]);
[email protected]93a41d72010-11-03 23:36:241025 ResetRangeChecksum();
[email protected]70cc56e42010-04-29 22:39:551026}
1027
1028double CustomHistogram::GetBucketSize(Count current, size_t i) const {
1029 return 1;
1030}
1031
1032//------------------------------------------------------------------------------
initial.commitd7cae122008-07-26 21:49:381033// The next section handles global (central) support for all histograms, as well
1034// as startup/teardown of this service.
1035//------------------------------------------------------------------------------
1036
1037// This singleton instance should be started during the single threaded portion
1038// of main(), and hence it is not thread safe. It initializes globals to
1039// provide support for all future calls.
1040StatisticsRecorder::StatisticsRecorder() {
1041 DCHECK(!histograms_);
[email protected]d14425542010-12-23 14:40:101042 if (lock_ == NULL) {
1043 // This will leak on purpose. It's the only way to make sure we won't race
1044 // against the static uninitialization of the module while one of our
1045 // static methods relying on the lock get called at an inappropriate time
1046 // during the termination phase. Since it's a static data member, we will
1047 // leak one per process, which would be similar to the instance allocated
1048 // during static initialization and released only on process termination.
[email protected]bc581a682011-01-01 23:16:201049 lock_ = new base::Lock;
[email protected]d14425542010-12-23 14:40:101050 }
[email protected]bc581a682011-01-01 23:16:201051 base::AutoLock auto_lock(*lock_);
initial.commitd7cae122008-07-26 21:49:381052 histograms_ = new HistogramMap;
[email protected]908de522011-10-20 00:55:001053 ranges_ = new RangesMap;
initial.commitd7cae122008-07-26 21:49:381054}
1055
1056StatisticsRecorder::~StatisticsRecorder() {
[email protected]d14425542010-12-23 14:40:101057 DCHECK(histograms_ && lock_);
initial.commitd7cae122008-07-26 21:49:381058
1059 if (dump_on_exit_) {
1060 std::string output;
1061 WriteGraph("", &output);
[email protected]a42d4632011-10-26 21:48:001062 DLOG(INFO) << output;
initial.commitd7cae122008-07-26 21:49:381063 }
initial.commitd7cae122008-07-26 21:49:381064 // Clean up.
[email protected]d14425542010-12-23 14:40:101065 HistogramMap* histograms = NULL;
1066 {
[email protected]bc581a682011-01-01 23:16:201067 base::AutoLock auto_lock(*lock_);
[email protected]d14425542010-12-23 14:40:101068 histograms = histograms_;
1069 histograms_ = NULL;
1070 }
[email protected]908de522011-10-20 00:55:001071 RangesMap* ranges = NULL;
1072 {
1073 base::AutoLock auto_lock(*lock_);
1074 ranges = ranges_;
1075 ranges_ = NULL;
1076 }
1077 // We are going to leak the histograms and the ranges.
[email protected]d14425542010-12-23 14:40:101078 delete histograms;
[email protected]908de522011-10-20 00:55:001079 delete ranges;
[email protected]d14425542010-12-23 14:40:101080 // We don't delete lock_ on purpose to avoid having to properly protect
1081 // against it going away after we checked for NULL in the static methods.
initial.commitd7cae122008-07-26 21:49:381082}
1083
1084// static
[email protected]d14425542010-12-23 14:40:101085bool StatisticsRecorder::IsActive() {
1086 if (lock_ == NULL)
1087 return false;
[email protected]bc581a682011-01-01 23:16:201088 base::AutoLock auto_lock(*lock_);
initial.commitd7cae122008-07-26 21:49:381089 return NULL != histograms_;
1090}
1091
[email protected]81ce9f3b2011-04-05 04:48:531092Histogram* StatisticsRecorder::RegisterOrDeleteDuplicate(Histogram* histogram) {
[email protected]9b3bbd62011-05-31 07:37:091093 // As per crbug.com/79322 the histograms are intentionally leaked, so we need
1094 // to annotate them. Because ANNOTATE_LEAKING_OBJECT_PTR may be used only once
1095 // for an object, the duplicates should not be annotated.
1096 // Callers are responsible for not calling RegisterOrDeleteDuplicate(ptr)
1097 // twice if (lock_ == NULL) || (!histograms_).
[email protected]81ce9f3b2011-04-05 04:48:531098 DCHECK(histogram->HasValidRangeChecksum());
[email protected]9b3bbd62011-05-31 07:37:091099 if (lock_ == NULL) {
1100 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
[email protected]81ce9f3b2011-04-05 04:48:531101 return histogram;
[email protected]9b3bbd62011-05-31 07:37:091102 }
[email protected]bc581a682011-01-01 23:16:201103 base::AutoLock auto_lock(*lock_);
[email protected]9b3bbd62011-05-31 07:37:091104 if (!histograms_) {
1105 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
[email protected]81ce9f3b2011-04-05 04:48:531106 return histogram;
[email protected]9b3bbd62011-05-31 07:37:091107 }
[email protected]81ce9f3b2011-04-05 04:48:531108 const std::string name = histogram->histogram_name();
[email protected]98359ce2011-03-05 06:22:241109 HistogramMap::iterator it = histograms_->find(name);
[email protected]cc82864b2010-08-17 19:46:511110 // Avoid overwriting a previous registration.
[email protected]81ce9f3b2011-04-05 04:48:531111 if (histograms_->end() == it) {
1112 (*histograms_)[name] = histogram;
[email protected]9b3bbd62011-05-31 07:37:091113 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
[email protected]908de522011-10-20 00:55:001114 RegisterOrDeleteDuplicateRanges(histogram);
1115 ++number_of_histograms_;
[email protected]81ce9f3b2011-04-05 04:48:531116 } else {
1117 delete histogram; // We already have one by this name.
1118 histogram = it->second;
1119 }
1120 return histogram;
initial.commitd7cae122008-07-26 21:49:381121}
1122
1123// static
[email protected]908de522011-10-20 00:55:001124void StatisticsRecorder::RegisterOrDeleteDuplicateRanges(Histogram* histogram) {
1125 DCHECK(histogram);
1126 CachedRanges* histogram_ranges = histogram->cached_ranges();
1127 DCHECK(histogram_ranges);
1128 uint32 checksum = histogram->range_checksum();
1129 histogram_ranges->SetRangeChecksum(checksum);
1130
1131 RangesMap::iterator ranges_it = ranges_->find(checksum);
1132 if (ranges_->end() == ranges_it) {
1133 // Register the new CachedRanges.
1134 std::list<CachedRanges*>* checksum_matching_list(
1135 new std::list<CachedRanges*>());
1136 checksum_matching_list->push_front(histogram_ranges);
1137 (*ranges_)[checksum] = checksum_matching_list;
1138 return;
1139 }
1140
1141 // Use the registered CachedRanges if the registered CachedRanges has same
1142 // ranges_ as |histogram|'s CachedRanges.
1143 std::list<CachedRanges*>* checksum_matching_list = ranges_it->second;
1144 std::list<CachedRanges*>::iterator checksum_matching_list_it;
1145 for (checksum_matching_list_it = checksum_matching_list->begin();
1146 checksum_matching_list_it != checksum_matching_list->end();
1147 ++checksum_matching_list_it) {
1148 CachedRanges* existing_histogram_ranges = *checksum_matching_list_it;
1149 DCHECK(existing_histogram_ranges);
1150 if (existing_histogram_ranges->Equals(histogram_ranges)) {
1151 histogram->set_cached_ranges(existing_histogram_ranges);
1152 ++number_of_vectors_saved_;
1153 saved_ranges_size_ += histogram_ranges->size();
1154 delete histogram_ranges;
1155 return;
1156 }
1157 }
1158
1159 // We haven't found a CachedRanges which has the same ranges. Register the
1160 // new CachedRanges.
1161 DCHECK(checksum_matching_list_it == checksum_matching_list->end());
1162 checksum_matching_list->push_front(histogram_ranges);
1163}
1164
1165// static
1166void StatisticsRecorder::CollectHistogramStats(const std::string& suffix) {
1167 static int uma_upload_attempt = 0;
1168 ++uma_upload_attempt;
1169 if (uma_upload_attempt == 1) {
1170 UMA_HISTOGRAM_COUNTS_10000(
1171 "Histogram.SharedRange.Count.FirstUpload." + suffix,
1172 number_of_histograms_);
1173 UMA_HISTOGRAM_COUNTS_10000(
1174 "Histogram.SharedRange.RangesSaved.FirstUpload." + suffix,
1175 number_of_vectors_saved_);
1176 UMA_HISTOGRAM_COUNTS(
1177 "Histogram.SharedRange.ElementsSaved.FirstUpload." + suffix,
1178 static_cast<int>(saved_ranges_size_));
1179 number_of_histograms_ = 0;
1180 number_of_vectors_saved_ = 0;
1181 saved_ranges_size_ = 0;
1182 return;
1183 }
1184 if (uma_upload_attempt == 2) {
1185 UMA_HISTOGRAM_COUNTS_10000(
1186 "Histogram.SharedRange.Count.SecondUpload." + suffix,
1187 number_of_histograms_);
1188 UMA_HISTOGRAM_COUNTS_10000(
1189 "Histogram.SharedRange.RangesSaved.SecondUpload." + suffix,
1190 number_of_vectors_saved_);
1191 UMA_HISTOGRAM_COUNTS(
1192 "Histogram.SharedRange.ElementsSaved.SecondUpload." + suffix,
1193 static_cast<int>(saved_ranges_size_));
1194 number_of_histograms_ = 0;
1195 number_of_vectors_saved_ = 0;
1196 saved_ranges_size_ = 0;
1197 return;
1198 }
1199 UMA_HISTOGRAM_COUNTS_10000(
1200 "Histogram.SharedRange.Count.RestOfUploads." + suffix,
1201 number_of_histograms_);
1202 UMA_HISTOGRAM_COUNTS_10000(
1203 "Histogram.SharedRange.RangesSaved.RestOfUploads." + suffix,
1204 number_of_vectors_saved_);
1205 UMA_HISTOGRAM_COUNTS(
1206 "Histogram.SharedRange.ElementsSaved.RestOfUploads." + suffix,
1207 static_cast<int>(saved_ranges_size_));
1208}
1209
1210// static
initial.commitd7cae122008-07-26 21:49:381211void StatisticsRecorder::WriteHTMLGraph(const std::string& query,
1212 std::string* output) {
[email protected]d14425542010-12-23 14:40:101213 if (!IsActive())
initial.commitd7cae122008-07-26 21:49:381214 return;
initial.commitd7cae122008-07-26 21:49:381215
1216 Histograms snapshot;
1217 GetSnapshot(query, &snapshot);
1218 for (Histograms::iterator it = snapshot.begin();
1219 it != snapshot.end();
[email protected]55e57d42009-02-25 06:10:171220 ++it) {
initial.commitd7cae122008-07-26 21:49:381221 (*it)->WriteHTMLGraph(output);
1222 output->append("<br><hr><br>");
1223 }
initial.commitd7cae122008-07-26 21:49:381224}
1225
1226// static
1227void StatisticsRecorder::WriteGraph(const std::string& query,
[email protected]55e57d42009-02-25 06:10:171228 std::string* output) {
[email protected]d14425542010-12-23 14:40:101229 if (!IsActive())
initial.commitd7cae122008-07-26 21:49:381230 return;
[email protected]835d7c82010-10-14 04:38:381231 if (query.length())
1232 StringAppendF(output, "Collections of histograms for %s\n", query.c_str());
1233 else
initial.commitd7cae122008-07-26 21:49:381234 output->append("Collections of all histograms\n");
1235
1236 Histograms snapshot;
1237 GetSnapshot(query, &snapshot);
1238 for (Histograms::iterator it = snapshot.begin();
1239 it != snapshot.end();
[email protected]55e57d42009-02-25 06:10:171240 ++it) {
initial.commitd7cae122008-07-26 21:49:381241 (*it)->WriteAscii(true, "\n", output);
1242 output->append("\n");
1243 }
1244}
1245
1246// static
1247void StatisticsRecorder::GetHistograms(Histograms* output) {
[email protected]d14425542010-12-23 14:40:101248 if (lock_ == NULL)
initial.commitd7cae122008-07-26 21:49:381249 return;
[email protected]bc581a682011-01-01 23:16:201250 base::AutoLock auto_lock(*lock_);
[email protected]d14425542010-12-23 14:40:101251 if (!histograms_)
1252 return;
initial.commitd7cae122008-07-26 21:49:381253 for (HistogramMap::iterator it = histograms_->begin();
1254 histograms_->end() != it;
[email protected]55e57d42009-02-25 06:10:171255 ++it) {
[email protected]2ef3748f2010-10-19 17:33:281256 DCHECK_EQ(it->first, it->second->histogram_name());
initial.commitd7cae122008-07-26 21:49:381257 output->push_back(it->second);
1258 }
1259}
1260
[email protected]e8829a192009-12-06 00:09:371261bool StatisticsRecorder::FindHistogram(const std::string& name,
[email protected]81ce9f3b2011-04-05 04:48:531262 Histogram** histogram) {
[email protected]d14425542010-12-23 14:40:101263 if (lock_ == NULL)
[email protected]e8829a192009-12-06 00:09:371264 return false;
[email protected]bc581a682011-01-01 23:16:201265 base::AutoLock auto_lock(*lock_);
[email protected]d14425542010-12-23 14:40:101266 if (!histograms_)
1267 return false;
[email protected]e8829a192009-12-06 00:09:371268 HistogramMap::iterator it = histograms_->find(name);
1269 if (histograms_->end() == it)
1270 return false;
1271 *histogram = it->second;
1272 return true;
[email protected]55e57d42009-02-25 06:10:171273}
1274
initial.commitd7cae122008-07-26 21:49:381275// private static
1276void StatisticsRecorder::GetSnapshot(const std::string& query,
1277 Histograms* snapshot) {
[email protected]d14425542010-12-23 14:40:101278 if (lock_ == NULL)
1279 return;
[email protected]bc581a682011-01-01 23:16:201280 base::AutoLock auto_lock(*lock_);
[email protected]d14425542010-12-23 14:40:101281 if (!histograms_)
1282 return;
initial.commitd7cae122008-07-26 21:49:381283 for (HistogramMap::iterator it = histograms_->begin();
1284 histograms_->end() != it;
[email protected]55e57d42009-02-25 06:10:171285 ++it) {
initial.commitd7cae122008-07-26 21:49:381286 if (it->first.find(query) != std::string::npos)
1287 snapshot->push_back(it->second);
1288 }
1289}
1290
[email protected]908de522011-10-20 00:55:001291CachedRanges::CachedRanges(size_t bucket_count, int initial_value)
1292 : ranges_(bucket_count, initial_value),
1293 range_checksum_(0) {
1294}
1295
1296CachedRanges::~CachedRanges() {
1297}
1298
1299void CachedRanges::SetBucketRange(size_t i, Histogram::Sample value) {
1300 DCHECK_LT(i, ranges_.size());
1301 DCHECK_GE(value, 0);
1302 ranges_[i] = value;
1303}
1304
1305bool CachedRanges::Equals(CachedRanges* other) const {
1306 if (range_checksum_ != other->range_checksum_)
1307 return false;
1308 if (ranges_.size() != other->ranges_.size())
1309 return false;
1310 for (size_t index = 0; index < ranges_.size(); ++index) {
1311 if (ranges_[index] != other->ranges_[index])
1312 return false;
1313 }
1314 return true;
1315}
1316
initial.commitd7cae122008-07-26 21:49:381317// static
1318StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
1319// static
[email protected]908de522011-10-20 00:55:001320StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL;
1321// static
[email protected]bc581a682011-01-01 23:16:201322base::Lock* StatisticsRecorder::lock_ = NULL;
initial.commitd7cae122008-07-26 21:49:381323// static
1324bool StatisticsRecorder::dump_on_exit_ = false;
[email protected]835d7c82010-10-14 04:38:381325} // namespace base