blob: b18b0309989dd5c0262b21eab3ed60fe748d9205 [file] [log] [blame]
[email protected]a93721e22012-01-06 02:13:281// Copyright (c) 2012 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
Alexei Svitkinee73f80a02017-07-18 00:08:3912#include <inttypes.h>
avi9b6f42932015-12-26 22:15:1413#include <limits.h>
initial.commitd7cae122008-07-26 21:49:3814#include <math.h>
[email protected]f1633932010-08-17 23:05:2815
16#include <algorithm>
initial.commitd7cae122008-07-26 21:49:3817#include <string>
jdoerrief1e72e32017-04-26 16:23:5518#include <utility>
initial.commitd7cae122008-07-26 21:49:3819
[email protected]ec0c0aa2012-08-14 02:02:0020#include "base/compiler_specific.h"
21#include "base/debug/alias.h"
initial.commitd7cae122008-07-26 21:49:3822#include "base/logging.h"
dcheng093de9b2016-04-04 21:25:5123#include "base/memory/ptr_util.h"
Gayane Petrosyan5745ac62018-03-23 01:45:2424#include "base/metrics/dummy_histogram.h"
Ilya Sherman16d5d5f42017-12-08 00:32:4425#include "base/metrics/histogram_functions.h"
bcwhiteb036e4322015-12-10 18:36:3426#include "base/metrics/metrics_hashes.h"
bcwhite33d95806a2016-03-16 02:37:4527#include "base/metrics/persistent_histogram_allocator.h"
bcwhite5cb99eb2016-02-01 21:07:5628#include "base/metrics/persistent_memory_allocator.h"
[email protected]877ef562012-10-20 02:56:1829#include "base/metrics/sample_vector.h"
[email protected]567d30e2012-07-13 21:48:2930#include "base/metrics/statistics_recorder.h"
[email protected]3f383852009-04-03 18:18:5531#include "base/pickle.h"
[email protected]d529cb02013-06-10 19:06:5732#include "base/strings/string_util.h"
33#include "base/strings/stringprintf.h"
[email protected]bc581a682011-01-01 23:16:2034#include "base/synchronization/lock.h"
[email protected]24a7ec52012-10-08 10:31:5035#include "base/values.h"
Alexei Svitkinee73f80a02017-07-18 00:08:3936#include "build/build_config.h"
initial.commitd7cae122008-07-26 21:49:3837
[email protected]835d7c82010-10-14 04:38:3838namespace base {
[email protected]e1acf6f2008-10-27 20:43:3339
[email protected]c50c21d2013-01-11 21:52:4440namespace {
41
42bool ReadHistogramArguments(PickleIterator* iter,
asvitkine24d3e9a2015-05-27 05:22:1443 std::string* histogram_name,
[email protected]c50c21d2013-01-11 21:52:4444 int* flags,
45 int* declared_min,
46 int* declared_max,
jam1eacd7e2016-02-08 22:48:1647 uint32_t* bucket_count,
avi9b6f42932015-12-26 22:15:1448 uint32_t* range_checksum) {
[email protected]c50c21d2013-01-11 21:52:4449 if (!iter->ReadString(histogram_name) ||
50 !iter->ReadInt(flags) ||
51 !iter->ReadInt(declared_min) ||
52 !iter->ReadInt(declared_max) ||
jam1eacd7e2016-02-08 22:48:1653 !iter->ReadUInt32(bucket_count) ||
[email protected]c50c21d2013-01-11 21:52:4454 !iter->ReadUInt32(range_checksum)) {
55 DLOG(ERROR) << "Pickle error decoding Histogram: " << *histogram_name;
56 return false;
57 }
58
59 // Since these fields may have come from an untrusted renderer, do additional
60 // checks above and beyond those in Histogram::Initialize()
61 if (*declared_max <= 0 ||
62 *declared_min <= 0 ||
63 *declared_max < *declared_min ||
64 INT_MAX / sizeof(HistogramBase::Count) <= *bucket_count ||
65 *bucket_count < 2) {
66 DLOG(ERROR) << "Values error decoding Histogram: " << histogram_name;
67 return false;
68 }
69
70 // We use the arguments to find or create the local version of the histogram
bcwhite05dc0922016-06-03 04:59:4471 // in this process, so we need to clear any IPC flag.
[email protected]c50c21d2013-01-11 21:52:4472 *flags &= ~HistogramBase::kIPCSerializationSourceFlag;
73
74 return true;
75}
76
77bool ValidateRangeChecksum(const HistogramBase& histogram,
avi9b6f42932015-12-26 22:15:1478 uint32_t range_checksum) {
Gayane Petrosyan5745ac62018-03-23 01:45:2479 // Normally, |histogram| should have type HISTOGRAM or be inherited from it.
80 // However, if it's expired, it will actually be a DUMMY_HISTOGRAM.
81 // Skip the checks in that case.
82 if (histogram.GetHistogramType() == DUMMY_HISTOGRAM)
83 return true;
[email protected]c50c21d2013-01-11 21:52:4484 const Histogram& casted_histogram =
85 static_cast<const Histogram&>(histogram);
86
87 return casted_histogram.bucket_ranges()->checksum() == range_checksum;
88}
89
90} // namespace
91
[email protected]34d062322012-08-01 21:34:0892typedef HistogramBase::Count Count;
93typedef HistogramBase::Sample Sample;
initial.commitd7cae122008-07-26 21:49:3894
[email protected]b122c0c2011-02-23 22:31:1895// static
jam1eacd7e2016-02-08 22:48:1696const uint32_t Histogram::kBucketCount_MAX = 16384u;
[email protected]b122c0c2011-02-23 22:31:1897
bcwhite5cb99eb2016-02-01 21:07:5698class Histogram::Factory {
99 public:
100 Factory(const std::string& name,
101 HistogramBase::Sample minimum,
102 HistogramBase::Sample maximum,
jam1eacd7e2016-02-08 22:48:16103 uint32_t bucket_count,
bcwhite5cb99eb2016-02-01 21:07:56104 int32_t flags)
105 : Factory(name, HISTOGRAM, minimum, maximum, bucket_count, flags) {}
106
107 // Create histogram based on construction parameters. Caller takes
108 // ownership of the returned object.
109 HistogramBase* Build();
110
111 protected:
112 Factory(const std::string& name,
113 HistogramType histogram_type,
114 HistogramBase::Sample minimum,
115 HistogramBase::Sample maximum,
jam1eacd7e2016-02-08 22:48:16116 uint32_t bucket_count,
bcwhite5cb99eb2016-02-01 21:07:56117 int32_t flags)
118 : name_(name),
119 histogram_type_(histogram_type),
120 minimum_(minimum),
121 maximum_(maximum),
122 bucket_count_(bucket_count),
123 flags_(flags) {}
124
125 // Create a BucketRanges structure appropriate for this histogram.
126 virtual BucketRanges* CreateRanges() {
127 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1);
128 Histogram::InitializeBucketRanges(minimum_, maximum_, ranges);
129 return ranges;
130 }
131
132 // Allocate the correct Histogram object off the heap (in case persistent
133 // memory is not available).
dcheng093de9b2016-04-04 21:25:51134 virtual std::unique_ptr<HistogramBase> HeapAlloc(const BucketRanges* ranges) {
Brian Whited1c91082017-11-03 14:46:42135 return WrapUnique(
136 new Histogram(GetPermanentName(name_), minimum_, maximum_, ranges));
bcwhite5cb99eb2016-02-01 21:07:56137 }
138
139 // Perform any required datafill on the just-created histogram. If
bcwhite3dd85c4f2016-03-17 13:21:56140 // overridden, be sure to call the "super" version -- this method may not
141 // always remain empty.
142 virtual void FillHistogram(HistogramBase* histogram) {}
bcwhite5cb99eb2016-02-01 21:07:56143
144 // These values are protected (instead of private) because they need to
145 // be accessible to methods of sub-classes in order to avoid passing
146 // unnecessary parameters everywhere.
147 const std::string& name_;
148 const HistogramType histogram_type_;
149 HistogramBase::Sample minimum_;
150 HistogramBase::Sample maximum_;
jam1eacd7e2016-02-08 22:48:16151 uint32_t bucket_count_;
bcwhite5cb99eb2016-02-01 21:07:56152 int32_t flags_;
153
154 private:
155 DISALLOW_COPY_AND_ASSIGN(Factory);
156};
157
158HistogramBase* Histogram::Factory::Build() {
bcwhite5cb99eb2016-02-01 21:07:56159 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name_);
160 if (!histogram) {
Gayane Petrosyan5745ac62018-03-23 01:45:24161 // TODO(gayane): |HashMetricName()| is called again in Histogram
162 // constructor. Refactor code to avoid the additional call.
163 bool should_record =
164 StatisticsRecorder::ShouldRecordHistogram(HashMetricName(name_));
165 if (!should_record)
166 return DummyHistogram::GetInstance();
bcwhite5cb99eb2016-02-01 21:07:56167 // To avoid racy destruction at shutdown, the following will be leaked.
bcwhite4ebd7272016-03-22 19:14:38168 const BucketRanges* created_ranges = CreateRanges();
169 const BucketRanges* registered_ranges =
bcwhite5cb99eb2016-02-01 21:07:56170 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(created_ranges);
171
172 // In most cases, the bucket-count, minimum, and maximum values are known
173 // when the code is written and so are passed in explicitly. In other
174 // cases (such as with a CustomHistogram), they are calculated dynamically
175 // at run-time. In the latter case, those ctor parameters are zero and
176 // the results extracted from the result of CreateRanges().
177 if (bucket_count_ == 0) {
jam1eacd7e2016-02-08 22:48:16178 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count());
bcwhite5cb99eb2016-02-01 21:07:56179 minimum_ = registered_ranges->range(1);
180 maximum_ = registered_ranges->range(bucket_count_ - 1);
181 }
bcwhitef1dec482017-07-06 14:39:11182 DCHECK_EQ(minimum_, registered_ranges->range(1));
183 DCHECK_EQ(maximum_, registered_ranges->range(bucket_count_ - 1));
bcwhite5cb99eb2016-02-01 21:07:56184
185 // Try to create the histogram using a "persistent" allocator. As of
bcwhite3dd85c4f2016-03-17 13:21:56186 // 2016-02-25, the availability of such is controlled by a base::Feature
bcwhite5cb99eb2016-02-01 21:07:56187 // that is off by default. If the allocator doesn't exist or if
188 // allocating from it fails, code below will allocate the histogram from
189 // the process heap.
bcwhite4ebd7272016-03-22 19:14:38190 PersistentHistogramAllocator::Reference histogram_ref = 0;
dcheng093de9b2016-04-04 21:25:51191 std::unique_ptr<HistogramBase> tentative_histogram;
bcwhite5e748c62016-04-06 02:03:53192 PersistentHistogramAllocator* allocator = GlobalHistogramAllocator::Get();
bcwhite5cb99eb2016-02-01 21:07:56193 if (allocator) {
bcwhite33d95806a2016-03-16 02:37:45194 tentative_histogram = allocator->AllocateHistogram(
bcwhite5cb99eb2016-02-01 21:07:56195 histogram_type_,
196 name_,
197 minimum_,
198 maximum_,
199 registered_ranges,
200 flags_,
201 &histogram_ref);
202 }
203
204 // Handle the case where no persistent allocator is present or the
205 // persistent allocation fails (perhaps because it is full).
206 if (!tentative_histogram) {
bcwhite4ebd7272016-03-22 19:14:38207 DCHECK(!histogram_ref); // Should never have been set.
208 DCHECK(!allocator); // Shouldn't have failed.
bcwhite5cb99eb2016-02-01 21:07:56209 flags_ &= ~HistogramBase::kIsPersistent;
210 tentative_histogram = HeapAlloc(registered_ranges);
bcwhite3dd85c4f2016-03-17 13:21:56211 tentative_histogram->SetFlags(flags_);
bcwhite5cb99eb2016-02-01 21:07:56212 }
213
bcwhite33d95806a2016-03-16 02:37:45214 FillHistogram(tentative_histogram.get());
215
216 // Register this histogram with the StatisticsRecorder. Keep a copy of
217 // the pointer value to tell later whether the locally created histogram
218 // was registered or deleted. The type is "void" because it could point
219 // to released memory after the following line.
220 const void* tentative_histogram_ptr = tentative_histogram.get();
221 histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(
222 tentative_histogram.release());
bcwhite5cb99eb2016-02-01 21:07:56223
224 // Persistent histograms need some follow-up processing.
bcwhite4ebd7272016-03-22 19:14:38225 if (histogram_ref) {
bcwhite33d95806a2016-03-16 02:37:45226 allocator->FinalizeHistogram(histogram_ref,
227 histogram == tentative_histogram_ptr);
bcwhite5cb99eb2016-02-01 21:07:56228 }
229 }
230
Brian Whitea958cc72018-04-19 18:24:16231 if (histogram_type_ != histogram->GetHistogramType() ||
232 (bucket_count_ != 0 && !histogram->HasConstructionArguments(
233 minimum_, maximum_, bucket_count_))) {
bcwhite5cb99eb2016-02-01 21:07:56234 // The construction arguments do not match the existing histogram. This can
235 // come about if an extension updates in the middle of a chrome run and has
Brian Whitea958cc72018-04-19 18:24:16236 // changed one of them, or simply by bad code within Chrome itself. A NULL
237 // return would cause Chrome to crash; better to just record it for later
238 // analysis.
239 UmaHistogramSparse("Histogram.MismatchedConstructionArguments",
240 static_cast<Sample>(HashMetricName(name_)));
241 DLOG(ERROR) << "Histogram " << name_
242 << " has mismatched construction arguments";
243 return DummyHistogram::GetInstance();
bcwhite5cb99eb2016-02-01 21:07:56244 }
245 return histogram;
246}
247
asvitkine24d3e9a2015-05-27 05:22:14248HistogramBase* Histogram::FactoryGet(const std::string& name,
[email protected]de415552013-01-23 04:12:17249 Sample minimum,
250 Sample maximum,
jam1eacd7e2016-02-08 22:48:16251 uint32_t bucket_count,
avi9b6f42932015-12-26 22:15:14252 int32_t flags) {
[email protected]e184be902012-08-07 04:49:24253 bool valid_arguments =
254 InspectConstructionArguments(name, &minimum, &maximum, &bucket_count);
255 DCHECK(valid_arguments);
[email protected]a93721e22012-01-06 02:13:28256
bcwhite5cb99eb2016-02-01 21:07:56257 return Factory(name, minimum, maximum, bucket_count, flags).Build();
[email protected]e8829a192009-12-06 00:09:37258}
259
asvitkine24d3e9a2015-05-27 05:22:14260HistogramBase* Histogram::FactoryTimeGet(const std::string& name,
[email protected]de415552013-01-23 04:12:17261 TimeDelta minimum,
262 TimeDelta maximum,
jam1eacd7e2016-02-08 22:48:16263 uint32_t bucket_count,
avi9b6f42932015-12-26 22:15:14264 int32_t flags) {
pkasting9cf9b94a2014-10-01 22:18:43265 return FactoryGet(name, static_cast<Sample>(minimum.InMilliseconds()),
266 static_cast<Sample>(maximum.InMilliseconds()), bucket_count,
267 flags);
[email protected]34d062322012-08-01 21:34:08268}
269
asvitkine5c2d5022015-06-19 00:37:50270HistogramBase* Histogram::FactoryGet(const char* name,
271 Sample minimum,
272 Sample maximum,
jam1eacd7e2016-02-08 22:48:16273 uint32_t bucket_count,
avi9b6f42932015-12-26 22:15:14274 int32_t flags) {
asvitkine5c2d5022015-06-19 00:37:50275 return FactoryGet(std::string(name), minimum, maximum, bucket_count, flags);
276}
277
278HistogramBase* Histogram::FactoryTimeGet(const char* name,
279 TimeDelta minimum,
280 TimeDelta maximum,
jam1eacd7e2016-02-08 22:48:16281 uint32_t bucket_count,
avi9b6f42932015-12-26 22:15:14282 int32_t flags) {
asvitkine5c2d5022015-06-19 00:37:50283 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count,
284 flags);
285}
286
dcheng093de9b2016-04-04 21:25:51287std::unique_ptr<HistogramBase> Histogram::PersistentCreate(
Brian Whited1c91082017-11-03 14:46:42288 const char* name,
bcwhitec85a1f822016-02-18 21:22:14289 Sample minimum,
290 Sample maximum,
291 const BucketRanges* ranges,
bcwhitefa8485b2017-05-01 16:43:25292 const DelayedPersistentAllocation& counts,
293 const DelayedPersistentAllocation& logged_counts,
bcwhitec85a1f822016-02-18 21:22:14294 HistogramSamples::Metadata* meta,
295 HistogramSamples::Metadata* logged_meta) {
dcheng093de9b2016-04-04 21:25:51296 return WrapUnique(new Histogram(name, minimum, maximum, ranges, counts,
bcwhitefa8485b2017-05-01 16:43:25297 logged_counts, meta, logged_meta));
bcwhite5cb99eb2016-02-01 21:07:56298}
299
[email protected]34d062322012-08-01 21:34:08300// Calculate what range of values are held in each bucket.
301// We have to be careful that we don't pick a ratio between starting points in
302// consecutive buckets that is sooo small, that the integer bounds are the same
303// (effectively making one bucket get no values). We need to avoid:
304// ranges(i) == ranges(i + 1)
305// To avoid that, we just do a fine-grained bucket width as far as we need to
306// until we get a ratio that moves us along at least 2 units at a time. From
307// that bucket onward we do use the exponential growth of buckets.
308//
309// static
310void Histogram::InitializeBucketRanges(Sample minimum,
311 Sample maximum,
[email protected]34d062322012-08-01 21:34:08312 BucketRanges* ranges) {
[email protected]34d062322012-08-01 21:34:08313 double log_max = log(static_cast<double>(maximum));
314 double log_ratio;
315 double log_next;
316 size_t bucket_index = 1;
317 Sample current = minimum;
318 ranges->set_range(bucket_index, current);
[email protected]15ce3842013-06-27 14:38:45319 size_t bucket_count = ranges->bucket_count();
[email protected]34d062322012-08-01 21:34:08320 while (bucket_count > ++bucket_index) {
321 double log_current;
322 log_current = log(static_cast<double>(current));
323 // Calculate the count'th root of the range.
324 log_ratio = (log_max - log_current) / (bucket_count - bucket_index);
325 // See where the next bucket would start.
326 log_next = log_current + log_ratio;
327 Sample next;
Peter Kasting8c3adfb2017-09-13 08:07:39328 next = static_cast<int>(std::round(exp(log_next)));
[email protected]34d062322012-08-01 21:34:08329 if (next > current)
330 current = next;
331 else
332 ++current; // Just do a narrow bucket, and keep trying.
333 ranges->set_range(bucket_index, current);
334 }
[email protected]15ce3842013-06-27 14:38:45335 ranges->set_range(ranges->bucket_count(), HistogramBase::kSampleType_MAX);
[email protected]34d062322012-08-01 21:34:08336 ranges->ResetChecksum();
337}
338
[email protected]2f7d9cd2012-09-22 03:42:12339// static
340const int Histogram::kCommonRaceBasedCountMismatch = 5;
[email protected]34d062322012-08-01 21:34:08341
bcwhitec85a1f822016-02-18 21:22:14342uint32_t Histogram::FindCorruption(const HistogramSamples& samples) const {
[email protected]34d062322012-08-01 21:34:08343 int inconsistencies = NO_INCONSISTENCIES;
344 Sample previous_range = -1; // Bottom range is always 0.
jam1eacd7e2016-02-08 22:48:16345 for (uint32_t index = 0; index < bucket_count(); ++index) {
[email protected]34d062322012-08-01 21:34:08346 int new_range = ranges(index);
347 if (previous_range >= new_range)
348 inconsistencies |= BUCKET_ORDER_ERROR;
349 previous_range = new_range;
350 }
351
352 if (!bucket_ranges()->HasValidChecksum())
353 inconsistencies |= RANGE_CHECKSUM_ERROR;
354
avi9b6f42932015-12-26 22:15:14355 int64_t delta64 = samples.redundant_count() - samples.TotalCount();
[email protected]34d062322012-08-01 21:34:08356 if (delta64 != 0) {
357 int delta = static_cast<int>(delta64);
358 if (delta != delta64)
359 delta = INT_MAX; // Flag all giant errors as INT_MAX.
[email protected]34d062322012-08-01 21:34:08360 if (delta > 0) {
[email protected]34d062322012-08-01 21:34:08361 if (delta > kCommonRaceBasedCountMismatch)
362 inconsistencies |= COUNT_HIGH_ERROR;
363 } else {
364 DCHECK_GT(0, delta);
[email protected]34d062322012-08-01 21:34:08365 if (-delta > kCommonRaceBasedCountMismatch)
366 inconsistencies |= COUNT_LOW_ERROR;
367 }
368 }
[email protected]cc7dec212013-03-01 03:53:25369 return inconsistencies;
[email protected]34d062322012-08-01 21:34:08370}
371
Brian White32052d5b2017-08-07 16:46:57372const BucketRanges* Histogram::bucket_ranges() const {
373 return unlogged_samples_->bucket_ranges();
374}
375
bcwhitef1dec482017-07-06 14:39:11376Sample Histogram::declared_min() const {
Brian White32052d5b2017-08-07 16:46:57377 const BucketRanges* ranges = bucket_ranges();
378 if (ranges->bucket_count() < 2)
bcwhitef1dec482017-07-06 14:39:11379 return -1;
Brian White32052d5b2017-08-07 16:46:57380 return ranges->range(1);
bcwhitef1dec482017-07-06 14:39:11381}
382
383Sample Histogram::declared_max() const {
Brian White32052d5b2017-08-07 16:46:57384 const BucketRanges* ranges = bucket_ranges();
385 if (ranges->bucket_count() < 2)
bcwhitef1dec482017-07-06 14:39:11386 return -1;
Brian White32052d5b2017-08-07 16:46:57387 return ranges->range(ranges->bucket_count() - 1);
bcwhitef1dec482017-07-06 14:39:11388}
389
jam1eacd7e2016-02-08 22:48:16390Sample Histogram::ranges(uint32_t i) const {
Brian White32052d5b2017-08-07 16:46:57391 return bucket_ranges()->range(i);
[email protected]34d062322012-08-01 21:34:08392}
393
jam1eacd7e2016-02-08 22:48:16394uint32_t Histogram::bucket_count() const {
Brian White32052d5b2017-08-07 16:46:57395 return static_cast<uint32_t>(bucket_ranges()->bucket_count());
[email protected]34d062322012-08-01 21:34:08396}
397
[email protected]34d062322012-08-01 21:34:08398// static
Brian Whited1c91082017-11-03 14:46:42399bool Histogram::InspectConstructionArguments(StringPiece name,
[email protected]34d062322012-08-01 21:34:08400 Sample* minimum,
401 Sample* maximum,
jam1eacd7e2016-02-08 22:48:16402 uint32_t* bucket_count) {
[email protected]34d062322012-08-01 21:34:08403 // Defensive code for backward compatibility.
404 if (*minimum < 1) {
[email protected]a5c7bd792012-08-02 00:29:04405 DVLOG(1) << "Histogram: " << name << " has bad minimum: " << *minimum;
[email protected]34d062322012-08-01 21:34:08406 *minimum = 1;
407 }
408 if (*maximum >= kSampleType_MAX) {
[email protected]a5c7bd792012-08-02 00:29:04409 DVLOG(1) << "Histogram: " << name << " has bad maximum: " << *maximum;
410 *maximum = kSampleType_MAX - 1;
[email protected]34d062322012-08-01 21:34:08411 }
[email protected]e184be902012-08-07 04:49:24412 if (*bucket_count >= kBucketCount_MAX) {
413 DVLOG(1) << "Histogram: " << name << " has bad bucket_count: "
414 << *bucket_count;
415 *bucket_count = kBucketCount_MAX - 1;
416 }
[email protected]34d062322012-08-01 21:34:08417
bcwhiteaaf2d3452017-04-26 19:17:47418 bool check_okay = true;
419
420 if (*minimum > *maximum) {
421 check_okay = false;
422 std::swap(*minimum, *maximum);
423 }
424 if (*maximum == *minimum) {
425 check_okay = false;
426 *maximum = *minimum + 1;
427 }
428 if (*bucket_count < 3) {
429 check_okay = false;
430 *bucket_count = 3;
431 }
asvitkinec49943d2017-05-25 19:29:47432 // Very high bucket counts are wasteful. Use a sparse histogram instead.
433 // Value of 10002 equals a user-supplied value of 10k + 2 overflow buckets.
434 constexpr uint32_t kMaxBucketCount = 10002;
435 if (*bucket_count > kMaxBucketCount) {
436 check_okay = false;
437 *bucket_count = kMaxBucketCount;
438 }
bcwhiteaaf2d3452017-04-26 19:17:47439 if (*bucket_count > static_cast<uint32_t>(*maximum - *minimum + 2)) {
440 check_okay = false;
441 *bucket_count = static_cast<uint32_t>(*maximum - *minimum + 2);
442 }
443
444 if (!check_okay) {
Ilya Sherman16d5d5f42017-12-08 00:32:44445 UmaHistogramSparse("Histogram.BadConstructionArguments",
446 static_cast<Sample>(HashMetricName(name)));
bcwhiteaaf2d3452017-04-26 19:17:47447 }
448
449 return check_okay;
[email protected]34d062322012-08-01 21:34:08450}
451
bcwhiteb036e4322015-12-10 18:36:34452uint64_t Histogram::name_hash() const {
altimin498c8382017-05-12 17:49:18453 return unlogged_samples_->id();
bcwhiteb036e4322015-12-10 18:36:34454}
455
[email protected]07c02402012-10-31 06:20:25456HistogramType Histogram::GetHistogramType() const {
457 return HISTOGRAM;
458}
459
[email protected]15ce3842013-06-27 14:38:45460bool Histogram::HasConstructionArguments(Sample expected_minimum,
461 Sample expected_maximum,
jam1eacd7e2016-02-08 22:48:16462 uint32_t expected_bucket_count) const {
bcwhitef1dec482017-07-06 14:39:11463 return (expected_bucket_count == bucket_count() &&
464 expected_minimum == declared_min() &&
465 expected_maximum == declared_max());
[email protected]abae9b022012-10-24 08:18:52466}
467
468void Histogram::Add(int value) {
amohammadkhan6779b5c32015-08-05 20:31:11469 AddCount(value, 1);
470}
471
472void Histogram::AddCount(int value, int count) {
[email protected]abae9b022012-10-24 08:18:52473 DCHECK_EQ(0, ranges(0));
[email protected]15ce3842013-06-27 14:38:45474 DCHECK_EQ(kSampleType_MAX, ranges(bucket_count()));
[email protected]abae9b022012-10-24 08:18:52475
476 if (value > kSampleType_MAX - 1)
477 value = kSampleType_MAX - 1;
478 if (value < 0)
479 value = 0;
amohammadkhan6779b5c32015-08-05 20:31:11480 if (count <= 0) {
481 NOTREACHED();
482 return;
483 }
altimin498c8382017-05-12 17:49:18484 unlogged_samples_->Accumulate(value, count);
simonhatchdf5a8142015-07-15 22:22:57485
486 FindAndRunCallback(value);
[email protected]abae9b022012-10-24 08:18:52487}
488
dcheng093de9b2016-04-04 21:25:51489std::unique_ptr<HistogramSamples> Histogram::SnapshotSamples() const {
altimin498c8382017-05-12 17:49:18490 return SnapshotAllSamples();
[email protected]abae9b022012-10-24 08:18:52491}
492
dcheng093de9b2016-04-04 21:25:51493std::unique_ptr<HistogramSamples> Histogram::SnapshotDelta() {
bcwhitef1dec482017-07-06 14:39:11494#if DCHECK_IS_ON()
bcwhite65e57d02016-05-13 14:39:40495 DCHECK(!final_delta_created_);
bcwhitef1dec482017-07-06 14:39:11496#endif
497
altimin498c8382017-05-12 17:49:18498 // The code below has subtle thread-safety guarantees! All changes to
499 // the underlying SampleVectors use atomic integer operations, which guarantee
500 // eventual consistency, but do not guarantee full synchronization between
501 // different entries in the SampleVector. In particular, this means that
502 // concurrent updates to the histogram might result in the reported sum not
503 // matching the individual bucket counts; or there being some buckets that are
504 // logically updated "together", but end up being only partially updated when
505 // a snapshot is captured. Note that this is why it's important to subtract
506 // exactly the snapshotted unlogged samples, rather than simply resetting the
507 // vector: this way, the next snapshot will include any concurrent updates
508 // missed by the current snapshot.
bcwhite65e57d02016-05-13 14:39:40509
altimin498c8382017-05-12 17:49:18510 std::unique_ptr<HistogramSamples> snapshot = SnapshotUnloggedSamples();
511 unlogged_samples_->Subtract(*snapshot);
bcwhitec85a1f822016-02-18 21:22:14512 logged_samples_->Add(*snapshot);
altimin498c8382017-05-12 17:49:18513
bcwhitec85a1f822016-02-18 21:22:14514 return snapshot;
515}
516
bcwhite65e57d02016-05-13 14:39:40517std::unique_ptr<HistogramSamples> Histogram::SnapshotFinalDelta() const {
bcwhitef1dec482017-07-06 14:39:11518#if DCHECK_IS_ON()
bcwhite65e57d02016-05-13 14:39:40519 DCHECK(!final_delta_created_);
520 final_delta_created_ = true;
bcwhitef1dec482017-07-06 14:39:11521#endif
bcwhite65e57d02016-05-13 14:39:40522
altimin498c8382017-05-12 17:49:18523 return SnapshotUnloggedSamples();
bcwhite65e57d02016-05-13 14:39:40524}
525
[email protected]c50c21d2013-01-11 21:52:44526void Histogram::AddSamples(const HistogramSamples& samples) {
altimin498c8382017-05-12 17:49:18527 unlogged_samples_->Add(samples);
[email protected]c50c21d2013-01-11 21:52:44528}
529
530bool Histogram::AddSamplesFromPickle(PickleIterator* iter) {
altimin498c8382017-05-12 17:49:18531 return unlogged_samples_->AddFromPickle(iter);
[email protected]c50c21d2013-01-11 21:52:44532}
533
[email protected]abae9b022012-10-24 08:18:52534// The following methods provide a graphical histogram display.
asvitkine24d3e9a2015-05-27 05:22:14535void Histogram::WriteHTMLGraph(std::string* output) const {
[email protected]abae9b022012-10-24 08:18:52536 // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc.
537 output->append("<PRE>");
538 WriteAsciiImpl(true, "<br>", output);
539 output->append("</PRE>");
540}
541
asvitkine24d3e9a2015-05-27 05:22:14542void Histogram::WriteAscii(std::string* output) const {
[email protected]abae9b022012-10-24 08:18:52543 WriteAsciiImpl(true, "\n", output);
544}
545
Daniel Cheng0d89f9222017-09-22 05:05:07546void Histogram::SerializeInfoImpl(Pickle* pickle) const {
[email protected]c50c21d2013-01-11 21:52:44547 DCHECK(bucket_ranges()->HasValidChecksum());
Daniel Cheng0d89f9222017-09-22 05:05:07548 pickle->WriteString(histogram_name());
549 pickle->WriteInt(flags());
550 pickle->WriteInt(declared_min());
551 pickle->WriteInt(declared_max());
552 pickle->WriteUInt32(bucket_count());
553 pickle->WriteUInt32(bucket_ranges()->checksum());
[email protected]c50c21d2013-01-11 21:52:44554}
555
bcwhitef1dec482017-07-06 14:39:11556// TODO(bcwhite): Remove minimum/maximum parameters from here and call chain.
Brian Whited1c91082017-11-03 14:46:42557Histogram::Histogram(const char* name,
[email protected]abae9b022012-10-24 08:18:52558 Sample minimum,
559 Sample maximum,
[email protected]abae9b022012-10-24 08:18:52560 const BucketRanges* ranges)
Brian Whitecaef6e12018-03-12 22:06:11561 : HistogramBase(name) {
Brian White7463677b2018-04-09 21:51:40562 DCHECK(ranges) << name << ": " << minimum << "-" << maximum;
bcwhiteb7bde182017-06-19 20:00:44563 unlogged_samples_.reset(new SampleVector(HashMetricName(name), ranges));
564 logged_samples_.reset(new SampleVector(unlogged_samples_->id(), ranges));
[email protected]abae9b022012-10-24 08:18:52565}
566
Brian Whited1c91082017-11-03 14:46:42567Histogram::Histogram(const char* name,
bcwhite5cb99eb2016-02-01 21:07:56568 Sample minimum,
569 Sample maximum,
570 const BucketRanges* ranges,
bcwhitefa8485b2017-05-01 16:43:25571 const DelayedPersistentAllocation& counts,
572 const DelayedPersistentAllocation& logged_counts,
bcwhitec85a1f822016-02-18 21:22:14573 HistogramSamples::Metadata* meta,
574 HistogramSamples::Metadata* logged_meta)
Brian Whitecaef6e12018-03-12 22:06:11575 : HistogramBase(name) {
Brian White7463677b2018-04-09 21:51:40576 DCHECK(ranges) << name << ": " << minimum << "-" << maximum;
bcwhiteb7bde182017-06-19 20:00:44577 unlogged_samples_.reset(
578 new PersistentSampleVector(HashMetricName(name), ranges, meta, counts));
579 logged_samples_.reset(new PersistentSampleVector(
580 unlogged_samples_->id(), ranges, logged_meta, logged_counts));
bcwhite5cb99eb2016-02-01 21:07:56581}
582
Chris Watkinsbb7211c2017-11-29 07:16:38583Histogram::~Histogram() = default;
[email protected]abae9b022012-10-24 08:18:52584
jam1eacd7e2016-02-08 22:48:16585bool Histogram::PrintEmptyBucket(uint32_t index) const {
[email protected]34d062322012-08-01 21:34:08586 return true;
587}
588
[email protected]34d062322012-08-01 21:34:08589// Use the actual bucket widths (like a linear histogram) until the widths get
590// over some transition value, and then use that transition width. Exponentials
591// get so big so fast (and we don't expect to see a lot of entries in the large
592// buckets), so we need this to make it possible to see what is going on and
593// not have 0-graphical-height buckets.
jam1eacd7e2016-02-08 22:48:16594double Histogram::GetBucketSize(Count current, uint32_t i) const {
[email protected]34d062322012-08-01 21:34:08595 DCHECK_GT(ranges(i + 1), ranges(i));
596 static const double kTransitionWidth = 5;
597 double denominator = ranges(i + 1) - ranges(i);
598 if (denominator > kTransitionWidth)
599 denominator = kTransitionWidth; // Stop trying to normalize.
600 return current/denominator;
601}
602
jam1eacd7e2016-02-08 22:48:16603const std::string Histogram::GetAsciiBucketRange(uint32_t i) const {
[email protected]f2bb3202013-04-05 21:21:54604 return GetSimpleAsciiBucketRange(ranges(i));
[email protected]34d062322012-08-01 21:34:08605}
606
[email protected]34d062322012-08-01 21:34:08607//------------------------------------------------------------------------------
608// Private methods
609
[email protected]c50c21d2013-01-11 21:52:44610// static
611HistogramBase* Histogram::DeserializeInfoImpl(PickleIterator* iter) {
asvitkine24d3e9a2015-05-27 05:22:14612 std::string histogram_name;
[email protected]c50c21d2013-01-11 21:52:44613 int flags;
614 int declared_min;
615 int declared_max;
jam1eacd7e2016-02-08 22:48:16616 uint32_t bucket_count;
avi9b6f42932015-12-26 22:15:14617 uint32_t range_checksum;
[email protected]c50c21d2013-01-11 21:52:44618
619 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min,
620 &declared_max, &bucket_count, &range_checksum)) {
Brian White7eb91482017-08-09 19:54:45621 return nullptr;
[email protected]c50c21d2013-01-11 21:52:44622 }
623
624 // Find or create the local version of the histogram in this process.
625 HistogramBase* histogram = Histogram::FactoryGet(
626 histogram_name, declared_min, declared_max, bucket_count, flags);
Brian White7eb91482017-08-09 19:54:45627 if (!histogram)
628 return nullptr;
[email protected]c50c21d2013-01-11 21:52:44629
Brian White7eb91482017-08-09 19:54:45630 // The serialized histogram might be corrupted.
631 if (!ValidateRangeChecksum(*histogram, range_checksum))
632 return nullptr;
633
[email protected]c50c21d2013-01-11 21:52:44634 return histogram;
635}
636
altimin498c8382017-05-12 17:49:18637std::unique_ptr<SampleVector> Histogram::SnapshotAllSamples() const {
638 std::unique_ptr<SampleVector> samples = SnapshotUnloggedSamples();
639 samples->Add(*logged_samples_);
640 return samples;
641}
642
643std::unique_ptr<SampleVector> Histogram::SnapshotUnloggedSamples() const {
dcheng093de9b2016-04-04 21:25:51644 std::unique_ptr<SampleVector> samples(
altimin498c8382017-05-12 17:49:18645 new SampleVector(unlogged_samples_->id(), bucket_ranges()));
646 samples->Add(*unlogged_samples_);
danakj0c8d4aa2015-11-25 05:29:58647 return samples;
[email protected]877ef562012-10-20 02:56:18648}
649
[email protected]34d062322012-08-01 21:34:08650void Histogram::WriteAsciiImpl(bool graph_it,
asvitkine24d3e9a2015-05-27 05:22:14651 const std::string& newline,
652 std::string* output) const {
[email protected]34d062322012-08-01 21:34:08653 // Get local (stack) copies of all effectively volatile class data so that we
654 // are consistent across our output activities.
altimin498c8382017-05-12 17:49:18655 std::unique_ptr<SampleVector> snapshot = SnapshotAllSamples();
[email protected]2f7d9cd2012-09-22 03:42:12656 Count sample_count = snapshot->TotalCount();
[email protected]34d062322012-08-01 21:34:08657
[email protected]2f7d9cd2012-09-22 03:42:12658 WriteAsciiHeader(*snapshot, sample_count, output);
[email protected]34d062322012-08-01 21:34:08659 output->append(newline);
660
661 // Prepare to normalize graphical rendering of bucket contents.
662 double max_size = 0;
663 if (graph_it)
[email protected]2f7d9cd2012-09-22 03:42:12664 max_size = GetPeakBucketSize(*snapshot);
[email protected]34d062322012-08-01 21:34:08665
666 // Calculate space needed to print bucket range numbers. Leave room to print
667 // nearly the largest bucket range without sliding over the histogram.
jam1eacd7e2016-02-08 22:48:16668 uint32_t largest_non_empty_bucket = bucket_count() - 1;
[email protected]2f7d9cd2012-09-22 03:42:12669 while (0 == snapshot->GetCountAtIndex(largest_non_empty_bucket)) {
[email protected]34d062322012-08-01 21:34:08670 if (0 == largest_non_empty_bucket)
671 break; // All buckets are empty.
672 --largest_non_empty_bucket;
673 }
674
675 // Calculate largest print width needed for any of our bucket range displays.
676 size_t print_width = 1;
jam1eacd7e2016-02-08 22:48:16677 for (uint32_t i = 0; i < bucket_count(); ++i) {
[email protected]2f7d9cd2012-09-22 03:42:12678 if (snapshot->GetCountAtIndex(i)) {
[email protected]34d062322012-08-01 21:34:08679 size_t width = GetAsciiBucketRange(i).size() + 1;
680 if (width > print_width)
681 print_width = width;
682 }
683 }
684
avi9b6f42932015-12-26 22:15:14685 int64_t remaining = sample_count;
686 int64_t past = 0;
[email protected]34d062322012-08-01 21:34:08687 // Output the actual histogram graph.
jam1eacd7e2016-02-08 22:48:16688 for (uint32_t i = 0; i < bucket_count(); ++i) {
[email protected]2f7d9cd2012-09-22 03:42:12689 Count current = snapshot->GetCountAtIndex(i);
[email protected]34d062322012-08-01 21:34:08690 if (!current && !PrintEmptyBucket(i))
691 continue;
692 remaining -= current;
asvitkine24d3e9a2015-05-27 05:22:14693 std::string range = GetAsciiBucketRange(i);
[email protected]34d062322012-08-01 21:34:08694 output->append(range);
695 for (size_t j = 0; range.size() + j < print_width + 1; ++j)
696 output->push_back(' ');
[email protected]2f7d9cd2012-09-22 03:42:12697 if (0 == current && i < bucket_count() - 1 &&
698 0 == snapshot->GetCountAtIndex(i + 1)) {
699 while (i < bucket_count() - 1 &&
700 0 == snapshot->GetCountAtIndex(i + 1)) {
[email protected]34d062322012-08-01 21:34:08701 ++i;
[email protected]2f7d9cd2012-09-22 03:42:12702 }
[email protected]34d062322012-08-01 21:34:08703 output->append("... ");
704 output->append(newline);
705 continue; // No reason to plot emptiness.
706 }
707 double current_size = GetBucketSize(current, i);
708 if (graph_it)
709 WriteAsciiBucketGraph(current_size, max_size, output);
710 WriteAsciiBucketContext(past, current, remaining, i, output);
711 output->append(newline);
712 past += current;
713 }
714 DCHECK_EQ(sample_count, past);
715}
716
bcwhitefa8485b2017-05-01 16:43:25717double Histogram::GetPeakBucketSize(const SampleVectorBase& samples) const {
[email protected]34d062322012-08-01 21:34:08718 double max = 0;
jam1eacd7e2016-02-08 22:48:16719 for (uint32_t i = 0; i < bucket_count() ; ++i) {
[email protected]2f7d9cd2012-09-22 03:42:12720 double current_size = GetBucketSize(samples.GetCountAtIndex(i), i);
[email protected]34d062322012-08-01 21:34:08721 if (current_size > max)
722 max = current_size;
723 }
724 return max;
725}
726
bcwhitefa8485b2017-05-01 16:43:25727void Histogram::WriteAsciiHeader(const SampleVectorBase& samples,
[email protected]34d062322012-08-01 21:34:08728 Count sample_count,
asvitkine24d3e9a2015-05-27 05:22:14729 std::string* output) const {
Brian Whited1c91082017-11-03 14:46:42730 StringAppendF(output, "Histogram: %s recorded %d samples", histogram_name(),
[email protected]34d062322012-08-01 21:34:08731 sample_count);
rkaplow035eb122016-09-28 21:48:36732 if (sample_count == 0) {
[email protected]2f7d9cd2012-09-22 03:42:12733 DCHECK_EQ(samples.sum(), 0);
[email protected]34d062322012-08-01 21:34:08734 } else {
rkaplow035eb122016-09-28 21:48:36735 double mean = static_cast<float>(samples.sum()) / sample_count;
736 StringAppendF(output, ", mean = %.1f", mean);
[email protected]34d062322012-08-01 21:34:08737 }
rkaplow035eb122016-09-28 21:48:36738 if (flags())
739 StringAppendF(output, " (flags = 0x%x)", flags());
[email protected]34d062322012-08-01 21:34:08740}
741
avi9b6f42932015-12-26 22:15:14742void Histogram::WriteAsciiBucketContext(const int64_t past,
[email protected]34d062322012-08-01 21:34:08743 const Count current,
avi9b6f42932015-12-26 22:15:14744 const int64_t remaining,
jam1eacd7e2016-02-08 22:48:16745 const uint32_t i,
asvitkine24d3e9a2015-05-27 05:22:14746 std::string* output) const {
[email protected]34d062322012-08-01 21:34:08747 double scaled_sum = (past + current + remaining) / 100.0;
748 WriteAsciiBucketValue(current, scaled_sum, output);
749 if (0 < i) {
750 double percentage = past / scaled_sum;
751 StringAppendF(output, " {%3.1f%%}", percentage);
752 }
753}
754
[email protected]24a7ec52012-10-08 10:31:50755void Histogram::GetParameters(DictionaryValue* params) const {
[email protected]07c02402012-10-31 06:20:25756 params->SetString("type", HistogramTypeToString(GetHistogramType()));
[email protected]24a7ec52012-10-08 10:31:50757 params->SetInteger("min", declared_min());
758 params->SetInteger("max", declared_max());
759 params->SetInteger("bucket_count", static_cast<int>(bucket_count()));
760}
761
[email protected]cdd98fc2013-05-10 09:32:58762void Histogram::GetCountAndBucketData(Count* count,
avi9b6f42932015-12-26 22:15:14763 int64_t* sum,
[email protected]cdd98fc2013-05-10 09:32:58764 ListValue* buckets) const {
altimin498c8382017-05-12 17:49:18765 std::unique_ptr<SampleVector> snapshot = SnapshotAllSamples();
[email protected]24a7ec52012-10-08 10:31:50766 *count = snapshot->TotalCount();
[email protected]cdd98fc2013-05-10 09:32:58767 *sum = snapshot->sum();
jam1eacd7e2016-02-08 22:48:16768 uint32_t index = 0;
769 for (uint32_t i = 0; i < bucket_count(); ++i) {
scottmgdcc933d2015-01-27 21:37:55770 Sample count_at_index = snapshot->GetCountAtIndex(i);
771 if (count_at_index > 0) {
dcheng093de9b2016-04-04 21:25:51772 std::unique_ptr<DictionaryValue> bucket_value(new DictionaryValue());
[email protected]24a7ec52012-10-08 10:31:50773 bucket_value->SetInteger("low", ranges(i));
774 if (i != bucket_count() - 1)
775 bucket_value->SetInteger("high", ranges(i + 1));
scottmgdcc933d2015-01-27 21:37:55776 bucket_value->SetInteger("count", count_at_index);
jdoerrief1e72e32017-04-26 16:23:55777 buckets->Set(index, std::move(bucket_value));
[email protected]24a7ec52012-10-08 10:31:50778 ++index;
779 }
780 }
781}
782
[email protected]34d062322012-08-01 21:34:08783//------------------------------------------------------------------------------
784// LinearHistogram: This histogram uses a traditional set of evenly spaced
785// buckets.
786//------------------------------------------------------------------------------
787
bcwhite5cb99eb2016-02-01 21:07:56788class LinearHistogram::Factory : public Histogram::Factory {
789 public:
790 Factory(const std::string& name,
791 HistogramBase::Sample minimum,
792 HistogramBase::Sample maximum,
jam1eacd7e2016-02-08 22:48:16793 uint32_t bucket_count,
bcwhite5cb99eb2016-02-01 21:07:56794 int32_t flags,
795 const DescriptionPair* descriptions)
796 : Histogram::Factory(name, LINEAR_HISTOGRAM, minimum, maximum,
797 bucket_count, flags) {
798 descriptions_ = descriptions;
799 }
800
801 protected:
802 BucketRanges* CreateRanges() override {
803 BucketRanges* ranges = new BucketRanges(bucket_count_ + 1);
804 LinearHistogram::InitializeBucketRanges(minimum_, maximum_, ranges);
805 return ranges;
806 }
807
dcheng093de9b2016-04-04 21:25:51808 std::unique_ptr<HistogramBase> HeapAlloc(
809 const BucketRanges* ranges) override {
Brian Whited1c91082017-11-03 14:46:42810 return WrapUnique(new LinearHistogram(GetPermanentName(name_), minimum_,
811 maximum_, ranges));
bcwhite5cb99eb2016-02-01 21:07:56812 }
813
814 void FillHistogram(HistogramBase* base_histogram) override {
815 Histogram::Factory::FillHistogram(base_histogram);
Gayane Petrosyan5745ac62018-03-23 01:45:24816 // Normally, |base_histogram| should have type LINEAR_HISTOGRAM or be
817 // inherited from it. However, if it's expired, it will actually be a
818 // DUMMY_HISTOGRAM. Skip filling in that case.
819 if (base_histogram->GetHistogramType() == DUMMY_HISTOGRAM)
820 return;
bcwhite5cb99eb2016-02-01 21:07:56821 LinearHistogram* histogram = static_cast<LinearHistogram*>(base_histogram);
822 // Set range descriptions.
823 if (descriptions_) {
824 for (int i = 0; descriptions_[i].description; ++i) {
825 histogram->bucket_description_[descriptions_[i].sample] =
826 descriptions_[i].description;
827 }
828 }
829 }
830
831 private:
832 const DescriptionPair* descriptions_;
833
834 DISALLOW_COPY_AND_ASSIGN(Factory);
835};
836
Chris Watkinsbb7211c2017-11-29 07:16:38837LinearHistogram::~LinearHistogram() = default;
[email protected]34d062322012-08-01 21:34:08838
asvitkine24d3e9a2015-05-27 05:22:14839HistogramBase* LinearHistogram::FactoryGet(const std::string& name,
[email protected]de415552013-01-23 04:12:17840 Sample minimum,
841 Sample maximum,
jam1eacd7e2016-02-08 22:48:16842 uint32_t bucket_count,
avi9b6f42932015-12-26 22:15:14843 int32_t flags) {
Brian White7eb91482017-08-09 19:54:45844 return FactoryGetWithRangeDescription(name, minimum, maximum, bucket_count,
Brian Whited1c91082017-11-03 14:46:42845 flags, NULL);
[email protected]07c02402012-10-31 06:20:25846}
847
asvitkine24d3e9a2015-05-27 05:22:14848HistogramBase* LinearHistogram::FactoryTimeGet(const std::string& name,
[email protected]de415552013-01-23 04:12:17849 TimeDelta minimum,
850 TimeDelta maximum,
jam1eacd7e2016-02-08 22:48:16851 uint32_t bucket_count,
avi9b6f42932015-12-26 22:15:14852 int32_t flags) {
pkasting9cf9b94a2014-10-01 22:18:43853 return FactoryGet(name, static_cast<Sample>(minimum.InMilliseconds()),
854 static_cast<Sample>(maximum.InMilliseconds()), bucket_count,
855 flags);
[email protected]07c02402012-10-31 06:20:25856}
857
asvitkine5c2d5022015-06-19 00:37:50858HistogramBase* LinearHistogram::FactoryGet(const char* name,
859 Sample minimum,
860 Sample maximum,
jam1eacd7e2016-02-08 22:48:16861 uint32_t bucket_count,
avi9b6f42932015-12-26 22:15:14862 int32_t flags) {
asvitkine5c2d5022015-06-19 00:37:50863 return FactoryGet(std::string(name), minimum, maximum, bucket_count, flags);
864}
865
866HistogramBase* LinearHistogram::FactoryTimeGet(const char* name,
867 TimeDelta minimum,
868 TimeDelta maximum,
jam1eacd7e2016-02-08 22:48:16869 uint32_t bucket_count,
avi9b6f42932015-12-26 22:15:14870 int32_t flags) {
asvitkine5c2d5022015-06-19 00:37:50871 return FactoryTimeGet(std::string(name), minimum, maximum, bucket_count,
872 flags);
873}
874
dcheng093de9b2016-04-04 21:25:51875std::unique_ptr<HistogramBase> LinearHistogram::PersistentCreate(
Brian Whited1c91082017-11-03 14:46:42876 const char* name,
bcwhite5cb99eb2016-02-01 21:07:56877 Sample minimum,
878 Sample maximum,
879 const BucketRanges* ranges,
bcwhitefa8485b2017-05-01 16:43:25880 const DelayedPersistentAllocation& counts,
881 const DelayedPersistentAllocation& logged_counts,
bcwhitec85a1f822016-02-18 21:22:14882 HistogramSamples::Metadata* meta,
883 HistogramSamples::Metadata* logged_meta) {
bcwhitefa8485b2017-05-01 16:43:25884 return WrapUnique(new LinearHistogram(name, minimum, maximum, ranges, counts,
885 logged_counts, meta, logged_meta));
bcwhite5cb99eb2016-02-01 21:07:56886}
887
[email protected]de415552013-01-23 04:12:17888HistogramBase* LinearHistogram::FactoryGetWithRangeDescription(
avi9b6f42932015-12-26 22:15:14889 const std::string& name,
890 Sample minimum,
891 Sample maximum,
jam1eacd7e2016-02-08 22:48:16892 uint32_t bucket_count,
avi9b6f42932015-12-26 22:15:14893 int32_t flags,
894 const DescriptionPair descriptions[]) {
[email protected]e184be902012-08-07 04:49:24895 bool valid_arguments = Histogram::InspectConstructionArguments(
896 name, &minimum, &maximum, &bucket_count);
897 DCHECK(valid_arguments);
[email protected]34d062322012-08-01 21:34:08898
bcwhite5cb99eb2016-02-01 21:07:56899 return Factory(name, minimum, maximum, bucket_count, flags, descriptions)
900 .Build();
[email protected]34d062322012-08-01 21:34:08901}
902
[email protected]07c02402012-10-31 06:20:25903HistogramType LinearHistogram::GetHistogramType() const {
[email protected]b7d08202011-01-25 17:29:39904 return LINEAR_HISTOGRAM;
905}
906
Brian Whited1c91082017-11-03 14:46:42907LinearHistogram::LinearHistogram(const char* name,
[email protected]835d7c82010-10-14 04:38:38908 Sample minimum,
909 Sample maximum,
[email protected]34d062322012-08-01 21:34:08910 const BucketRanges* ranges)
Brian Whited1c91082017-11-03 14:46:42911 : Histogram(name, minimum, maximum, ranges) {}
initial.commitd7cae122008-07-26 21:49:38912
bcwhitefa8485b2017-05-01 16:43:25913LinearHistogram::LinearHistogram(
Brian Whited1c91082017-11-03 14:46:42914 const char* name,
bcwhitefa8485b2017-05-01 16:43:25915 Sample minimum,
916 Sample maximum,
917 const BucketRanges* ranges,
918 const DelayedPersistentAllocation& counts,
919 const DelayedPersistentAllocation& logged_counts,
920 HistogramSamples::Metadata* meta,
921 HistogramSamples::Metadata* logged_meta)
922 : Histogram(name,
923 minimum,
924 maximum,
925 ranges,
926 counts,
927 logged_counts,
928 meta,
929 logged_meta) {}
bcwhite5cb99eb2016-02-01 21:07:56930
jam1eacd7e2016-02-08 22:48:16931double LinearHistogram::GetBucketSize(Count current, uint32_t i) const {
[email protected]2ef3748f2010-10-19 17:33:28932 DCHECK_GT(ranges(i + 1), ranges(i));
initial.commitd7cae122008-07-26 21:49:38933 // Adjacent buckets with different widths would have "surprisingly" many (few)
934 // samples in a histogram if we didn't normalize this way.
935 double denominator = ranges(i + 1) - ranges(i);
936 return current/denominator;
937}
938
jam1eacd7e2016-02-08 22:48:16939const std::string LinearHistogram::GetAsciiBucketRange(uint32_t i) const {
[email protected]b7d08202011-01-25 17:29:39940 int range = ranges(i);
941 BucketDescriptionMap::const_iterator it = bucket_description_.find(range);
942 if (it == bucket_description_.end())
943 return Histogram::GetAsciiBucketRange(i);
944 return it->second;
945}
946
jam1eacd7e2016-02-08 22:48:16947bool LinearHistogram::PrintEmptyBucket(uint32_t index) const {
[email protected]b7d08202011-01-25 17:29:39948 return bucket_description_.find(ranges(index)) == bucket_description_.end();
949}
950
[email protected]34d062322012-08-01 21:34:08951// static
952void LinearHistogram::InitializeBucketRanges(Sample minimum,
953 Sample maximum,
[email protected]34d062322012-08-01 21:34:08954 BucketRanges* ranges) {
[email protected]34d062322012-08-01 21:34:08955 double min = minimum;
956 double max = maximum;
[email protected]15ce3842013-06-27 14:38:45957 size_t bucket_count = ranges->bucket_count();
958 for (size_t i = 1; i < bucket_count; ++i) {
[email protected]34d062322012-08-01 21:34:08959 double linear_range =
[email protected]15ce3842013-06-27 14:38:45960 (min * (bucket_count - 1 - i) + max * (i - 1)) / (bucket_count - 2);
[email protected]34d062322012-08-01 21:34:08961 ranges->set_range(i, static_cast<Sample>(linear_range + 0.5));
962 }
[email protected]15ce3842013-06-27 14:38:45963 ranges->set_range(ranges->bucket_count(), HistogramBase::kSampleType_MAX);
[email protected]34d062322012-08-01 21:34:08964 ranges->ResetChecksum();
965}
[email protected]b7d08202011-01-25 17:29:39966
[email protected]c50c21d2013-01-11 21:52:44967// static
968HistogramBase* LinearHistogram::DeserializeInfoImpl(PickleIterator* iter) {
asvitkine24d3e9a2015-05-27 05:22:14969 std::string histogram_name;
[email protected]c50c21d2013-01-11 21:52:44970 int flags;
971 int declared_min;
972 int declared_max;
jam1eacd7e2016-02-08 22:48:16973 uint32_t bucket_count;
avi9b6f42932015-12-26 22:15:14974 uint32_t range_checksum;
[email protected]c50c21d2013-01-11 21:52:44975
976 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min,
977 &declared_max, &bucket_count, &range_checksum)) {
Brian White7eb91482017-08-09 19:54:45978 return nullptr;
[email protected]c50c21d2013-01-11 21:52:44979 }
980
981 HistogramBase* histogram = LinearHistogram::FactoryGet(
982 histogram_name, declared_min, declared_max, bucket_count, flags);
Brian White82027ff5d2017-08-21 19:50:22983 if (!histogram)
984 return nullptr;
985
[email protected]c50c21d2013-01-11 21:52:44986 if (!ValidateRangeChecksum(*histogram, range_checksum)) {
987 // The serialized histogram might be corrupted.
Brian White7eb91482017-08-09 19:54:45988 return nullptr;
[email protected]c50c21d2013-01-11 21:52:44989 }
990 return histogram;
991}
992
initial.commitd7cae122008-07-26 21:49:38993//------------------------------------------------------------------------------
[email protected]e8829a192009-12-06 00:09:37994// This section provides implementation for BooleanHistogram.
995//------------------------------------------------------------------------------
996
bcwhite5cb99eb2016-02-01 21:07:56997class BooleanHistogram::Factory : public Histogram::Factory {
998 public:
999 Factory(const std::string& name, int32_t flags)
1000 : Histogram::Factory(name, BOOLEAN_HISTOGRAM, 1, 2, 3, flags) {}
1001
1002 protected:
1003 BucketRanges* CreateRanges() override {
1004 BucketRanges* ranges = new BucketRanges(3 + 1);
[email protected]15ce3842013-06-27 14:38:451005 LinearHistogram::InitializeBucketRanges(1, 2, ranges);
bcwhite5cb99eb2016-02-01 21:07:561006 return ranges;
[email protected]e8829a192009-12-06 00:09:371007 }
1008
dcheng093de9b2016-04-04 21:25:511009 std::unique_ptr<HistogramBase> HeapAlloc(
1010 const BucketRanges* ranges) override {
Brian Whited1c91082017-11-03 14:46:421011 return WrapUnique(new BooleanHistogram(GetPermanentName(name_), ranges));
bcwhite5cb99eb2016-02-01 21:07:561012 }
1013
1014 private:
1015 DISALLOW_COPY_AND_ASSIGN(Factory);
1016};
1017
1018HistogramBase* BooleanHistogram::FactoryGet(const std::string& name,
1019 int32_t flags) {
1020 return Factory(name, flags).Build();
[email protected]e8829a192009-12-06 00:09:371021}
1022
avi9b6f42932015-12-26 22:15:141023HistogramBase* BooleanHistogram::FactoryGet(const char* name, int32_t flags) {
asvitkine5c2d5022015-06-19 00:37:501024 return FactoryGet(std::string(name), flags);
1025}
1026
dcheng093de9b2016-04-04 21:25:511027std::unique_ptr<HistogramBase> BooleanHistogram::PersistentCreate(
Brian Whited1c91082017-11-03 14:46:421028 const char* name,
bcwhite5cb99eb2016-02-01 21:07:561029 const BucketRanges* ranges,
bcwhitefa8485b2017-05-01 16:43:251030 const DelayedPersistentAllocation& counts,
1031 const DelayedPersistentAllocation& logged_counts,
bcwhitec85a1f822016-02-18 21:22:141032 HistogramSamples::Metadata* meta,
1033 HistogramSamples::Metadata* logged_meta) {
bcwhitefa8485b2017-05-01 16:43:251034 return WrapUnique(new BooleanHistogram(name, ranges, counts, logged_counts,
1035 meta, logged_meta));
bcwhite5cb99eb2016-02-01 21:07:561036}
1037
[email protected]07c02402012-10-31 06:20:251038HistogramType BooleanHistogram::GetHistogramType() const {
[email protected]5d91c9e2010-07-28 17:25:281039 return BOOLEAN_HISTOGRAM;
1040}
1041
Brian Whited1c91082017-11-03 14:46:421042BooleanHistogram::BooleanHistogram(const char* name, const BucketRanges* ranges)
[email protected]15ce3842013-06-27 14:38:451043 : LinearHistogram(name, 1, 2, ranges) {}
initial.commitd7cae122008-07-26 21:49:381044
bcwhitefa8485b2017-05-01 16:43:251045BooleanHistogram::BooleanHistogram(
Brian Whited1c91082017-11-03 14:46:421046 const char* name,
bcwhitefa8485b2017-05-01 16:43:251047 const BucketRanges* ranges,
1048 const DelayedPersistentAllocation& counts,
1049 const DelayedPersistentAllocation& logged_counts,
1050 HistogramSamples::Metadata* meta,
1051 HistogramSamples::Metadata* logged_meta)
1052 : LinearHistogram(name,
1053 1,
1054 2,
1055 ranges,
1056 counts,
1057 logged_counts,
1058 meta,
bcwhitec85a1f822016-02-18 21:22:141059 logged_meta) {}
bcwhite5cb99eb2016-02-01 21:07:561060
[email protected]c50c21d2013-01-11 21:52:441061HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) {
asvitkine24d3e9a2015-05-27 05:22:141062 std::string histogram_name;
[email protected]c50c21d2013-01-11 21:52:441063 int flags;
1064 int declared_min;
1065 int declared_max;
jam1eacd7e2016-02-08 22:48:161066 uint32_t bucket_count;
avi9b6f42932015-12-26 22:15:141067 uint32_t range_checksum;
[email protected]c50c21d2013-01-11 21:52:441068
1069 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min,
1070 &declared_max, &bucket_count, &range_checksum)) {
Brian White7eb91482017-08-09 19:54:451071 return nullptr;
[email protected]c50c21d2013-01-11 21:52:441072 }
1073
1074 HistogramBase* histogram = BooleanHistogram::FactoryGet(
1075 histogram_name, flags);
Brian White82027ff5d2017-08-21 19:50:221076 if (!histogram)
1077 return nullptr;
1078
[email protected]c50c21d2013-01-11 21:52:441079 if (!ValidateRangeChecksum(*histogram, range_checksum)) {
1080 // The serialized histogram might be corrupted.
Brian White7eb91482017-08-09 19:54:451081 return nullptr;
[email protected]c50c21d2013-01-11 21:52:441082 }
1083 return histogram;
1084}
1085
initial.commitd7cae122008-07-26 21:49:381086//------------------------------------------------------------------------------
[email protected]70cc56e42010-04-29 22:39:551087// CustomHistogram:
1088//------------------------------------------------------------------------------
1089
bcwhite5cb99eb2016-02-01 21:07:561090class CustomHistogram::Factory : public Histogram::Factory {
1091 public:
1092 Factory(const std::string& name,
1093 const std::vector<Sample>* custom_ranges,
1094 int32_t flags)
1095 : Histogram::Factory(name, CUSTOM_HISTOGRAM, 0, 0, 0, flags) {
1096 custom_ranges_ = custom_ranges;
1097 }
1098
1099 protected:
1100 BucketRanges* CreateRanges() override {
1101 // Remove the duplicates in the custom ranges array.
1102 std::vector<int> ranges = *custom_ranges_;
1103 ranges.push_back(0); // Ensure we have a zero value.
1104 ranges.push_back(HistogramBase::kSampleType_MAX);
1105 std::sort(ranges.begin(), ranges.end());
1106 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end());
1107
1108 BucketRanges* bucket_ranges = new BucketRanges(ranges.size());
jam1eacd7e2016-02-08 22:48:161109 for (uint32_t i = 0; i < ranges.size(); i++) {
bcwhite5cb99eb2016-02-01 21:07:561110 bucket_ranges->set_range(i, ranges[i]);
1111 }
1112 bucket_ranges->ResetChecksum();
1113 return bucket_ranges;
1114 }
1115
dcheng093de9b2016-04-04 21:25:511116 std::unique_ptr<HistogramBase> HeapAlloc(
1117 const BucketRanges* ranges) override {
Brian Whited1c91082017-11-03 14:46:421118 return WrapUnique(new CustomHistogram(GetPermanentName(name_), ranges));
bcwhite5cb99eb2016-02-01 21:07:561119 }
1120
1121 private:
1122 const std::vector<Sample>* custom_ranges_;
1123
1124 DISALLOW_COPY_AND_ASSIGN(Factory);
1125};
1126
asvitkine24d3e9a2015-05-27 05:22:141127HistogramBase* CustomHistogram::FactoryGet(
1128 const std::string& name,
1129 const std::vector<Sample>& custom_ranges,
avi9b6f42932015-12-26 22:15:141130 int32_t flags) {
[email protected]34d062322012-08-01 21:34:081131 CHECK(ValidateCustomRanges(custom_ranges));
[email protected]70cc56e42010-04-29 22:39:551132
bcwhite5cb99eb2016-02-01 21:07:561133 return Factory(name, &custom_ranges, flags).Build();
[email protected]70cc56e42010-04-29 22:39:551134}
1135
asvitkine5c2d5022015-06-19 00:37:501136HistogramBase* CustomHistogram::FactoryGet(
1137 const char* name,
1138 const std::vector<Sample>& custom_ranges,
avi9b6f42932015-12-26 22:15:141139 int32_t flags) {
asvitkine5c2d5022015-06-19 00:37:501140 return FactoryGet(std::string(name), custom_ranges, flags);
1141}
1142
dcheng093de9b2016-04-04 21:25:511143std::unique_ptr<HistogramBase> CustomHistogram::PersistentCreate(
Brian Whited1c91082017-11-03 14:46:421144 const char* name,
bcwhite5cb99eb2016-02-01 21:07:561145 const BucketRanges* ranges,
bcwhitefa8485b2017-05-01 16:43:251146 const DelayedPersistentAllocation& counts,
1147 const DelayedPersistentAllocation& logged_counts,
bcwhitec85a1f822016-02-18 21:22:141148 HistogramSamples::Metadata* meta,
1149 HistogramSamples::Metadata* logged_meta) {
bcwhitefa8485b2017-05-01 16:43:251150 return WrapUnique(new CustomHistogram(name, ranges, counts, logged_counts,
1151 meta, logged_meta));
bcwhite5cb99eb2016-02-01 21:07:561152}
1153
[email protected]07c02402012-10-31 06:20:251154HistogramType CustomHistogram::GetHistogramType() const {
[email protected]5d91c9e2010-07-28 17:25:281155 return CUSTOM_HISTOGRAM;
1156}
1157
[email protected]961fefb2011-05-24 13:59:581158// static
asvitkine24d3e9a2015-05-27 05:22:141159std::vector<Sample> CustomHistogram::ArrayToCustomRanges(
jam1eacd7e2016-02-08 22:48:161160 const Sample* values, uint32_t num_values) {
asvitkine24d3e9a2015-05-27 05:22:141161 std::vector<Sample> all_values;
jam1eacd7e2016-02-08 22:48:161162 for (uint32_t i = 0; i < num_values; ++i) {
[email protected]961fefb2011-05-24 13:59:581163 Sample value = values[i];
1164 all_values.push_back(value);
1165
1166 // Ensure that a guard bucket is added. If we end up with duplicate
1167 // values, FactoryGet will take care of removing them.
1168 all_values.push_back(value + 1);
1169 }
1170 return all_values;
1171}
1172
Brian Whited1c91082017-11-03 14:46:421173CustomHistogram::CustomHistogram(const char* name, const BucketRanges* ranges)
[email protected]34d062322012-08-01 21:34:081174 : Histogram(name,
1175 ranges->range(1),
[email protected]15ce3842013-06-27 14:38:451176 ranges->range(ranges->bucket_count() - 1),
[email protected]34d062322012-08-01 21:34:081177 ranges) {}
[email protected]70cc56e42010-04-29 22:39:551178
bcwhitefa8485b2017-05-01 16:43:251179CustomHistogram::CustomHistogram(
Brian Whited1c91082017-11-03 14:46:421180 const char* name,
bcwhitefa8485b2017-05-01 16:43:251181 const BucketRanges* ranges,
1182 const DelayedPersistentAllocation& counts,
1183 const DelayedPersistentAllocation& logged_counts,
1184 HistogramSamples::Metadata* meta,
1185 HistogramSamples::Metadata* logged_meta)
bcwhite5cb99eb2016-02-01 21:07:561186 : Histogram(name,
1187 ranges->range(1),
1188 ranges->range(ranges->bucket_count() - 1),
1189 ranges,
1190 counts,
bcwhitec85a1f822016-02-18 21:22:141191 logged_counts,
bcwhitec85a1f822016-02-18 21:22:141192 meta,
1193 logged_meta) {}
bcwhite5cb99eb2016-02-01 21:07:561194
Daniel Cheng0d89f9222017-09-22 05:05:071195void CustomHistogram::SerializeInfoImpl(Pickle* pickle) const {
1196 Histogram::SerializeInfoImpl(pickle);
[email protected]cd56dff2011-11-13 04:19:151197
[email protected]c50c21d2013-01-11 21:52:441198 // Serialize ranges. First and last ranges are alwasy 0 and INT_MAX, so don't
1199 // write them.
Daniel Cheng0d89f9222017-09-22 05:05:071200 for (uint32_t i = 1; i < bucket_ranges()->bucket_count(); ++i)
1201 pickle->WriteInt(bucket_ranges()->range(i));
[email protected]cd56dff2011-11-13 04:19:151202}
1203
jam1eacd7e2016-02-08 22:48:161204double CustomHistogram::GetBucketSize(Count current, uint32_t i) const {
brianderson7406e5c2016-06-23 21:34:471205 // If this is a histogram of enum values, normalizing the bucket count
1206 // by the bucket range is not helpful, so just return the bucket count.
1207 return current;
[email protected]70cc56e42010-04-29 22:39:551208}
1209
[email protected]34d062322012-08-01 21:34:081210// static
[email protected]c50c21d2013-01-11 21:52:441211HistogramBase* CustomHistogram::DeserializeInfoImpl(PickleIterator* iter) {
asvitkine24d3e9a2015-05-27 05:22:141212 std::string histogram_name;
[email protected]c50c21d2013-01-11 21:52:441213 int flags;
1214 int declared_min;
1215 int declared_max;
jam1eacd7e2016-02-08 22:48:161216 uint32_t bucket_count;
avi9b6f42932015-12-26 22:15:141217 uint32_t range_checksum;
[email protected]c50c21d2013-01-11 21:52:441218
1219 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min,
1220 &declared_max, &bucket_count, &range_checksum)) {
Brian White7eb91482017-08-09 19:54:451221 return nullptr;
[email protected]c50c21d2013-01-11 21:52:441222 }
1223
1224 // First and last ranges are not serialized.
asvitkine24d3e9a2015-05-27 05:22:141225 std::vector<Sample> sample_ranges(bucket_count - 1);
[email protected]c50c21d2013-01-11 21:52:441226
jam1eacd7e2016-02-08 22:48:161227 for (uint32_t i = 0; i < sample_ranges.size(); ++i) {
[email protected]c50c21d2013-01-11 21:52:441228 if (!iter->ReadInt(&sample_ranges[i]))
Brian White7eb91482017-08-09 19:54:451229 return nullptr;
[email protected]c50c21d2013-01-11 21:52:441230 }
1231
1232 HistogramBase* histogram = CustomHistogram::FactoryGet(
1233 histogram_name, sample_ranges, flags);
Brian White82027ff5d2017-08-21 19:50:221234 if (!histogram)
1235 return nullptr;
1236
[email protected]c50c21d2013-01-11 21:52:441237 if (!ValidateRangeChecksum(*histogram, range_checksum)) {
1238 // The serialized histogram might be corrupted.
Brian White7eb91482017-08-09 19:54:451239 return nullptr;
[email protected]c50c21d2013-01-11 21:52:441240 }
1241 return histogram;
1242}
1243
1244// static
[email protected]34d062322012-08-01 21:34:081245bool CustomHistogram::ValidateCustomRanges(
asvitkine24d3e9a2015-05-27 05:22:141246 const std::vector<Sample>& custom_ranges) {
[email protected]640d95ef2012-08-04 06:23:031247 bool has_valid_range = false;
jam1eacd7e2016-02-08 22:48:161248 for (uint32_t i = 0; i < custom_ranges.size(); i++) {
[email protected]640d95ef2012-08-04 06:23:031249 Sample sample = custom_ranges[i];
1250 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1)
[email protected]34d062322012-08-01 21:34:081251 return false;
[email protected]640d95ef2012-08-04 06:23:031252 if (sample != 0)
1253 has_valid_range = true;
[email protected]34d062322012-08-01 21:34:081254 }
[email protected]640d95ef2012-08-04 06:23:031255 return has_valid_range;
[email protected]34d062322012-08-01 21:34:081256}
1257
[email protected]835d7c82010-10-14 04:38:381258} // namespace base