Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / base / metrics / bucket_ranges.h
blobfe1152f5dbc714642bb258040d62ecc4fcaef8c5
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // BucketRanges stores the vector of ranges that delimit what samples are
6 // tallied in the corresponding buckets of a histogram. Histograms that have
7 // same ranges for all their corresponding buckets should share the same
8 // BucketRanges object.
9 //
10 // E.g. A 5 buckets LinearHistogram with 1 as minimal value and 4 as maximal
11 // value will need a BucketRanges with 6 ranges:
12 // 0, 1, 2, 3, 4, INT_MAX
14 // TODO(kaiwang): Currently we keep all negative values in 0~1 bucket. Consider
15 // changing 0 to INT_MIN.
17 #ifndef BASE_METRICS_BUCKET_RANGES_H_
18 #define BASE_METRICS_BUCKET_RANGES_H_
20 #include <vector>
22 #include "base/base_export.h"
23 #include "base/basictypes.h"
24 #include "base/gtest_prod_util.h"
25 #include "base/metrics/histogram_base.h"
27 namespace base {
29 class BASE_EXPORT BucketRanges {
30 public:
31 typedef std::vector<HistogramBase::Sample> Ranges;
33 explicit BucketRanges(size_t num_ranges);
34 ~BucketRanges();
36 size_t size() const { return ranges_.size(); }
37 HistogramBase::Sample range(size_t i) const { return ranges_[i]; }
38 void set_range(size_t i, HistogramBase::Sample value);
39 uint32 checksum() const { return checksum_; }
40 void set_checksum(uint32 checksum) { checksum_ = checksum; }
42 // A bucket is defined by a consecutive pair of entries in |ranges|, so there
43 // is one fewer bucket than there are ranges. For example, if |ranges| is
44 // [0, 1, 3, 7, INT_MAX], then the buckets in this histogram are
45 // [0, 1), [1, 3), [3, 7), and [7, INT_MAX).
46 size_t bucket_count() const { return ranges_.size() - 1; }
48 // Checksum methods to verify whether the ranges are corrupted (e.g. bad
49 // memory access).
50 uint32 CalculateChecksum() const;
51 bool HasValidChecksum() const;
52 void ResetChecksum();
54 // Return true iff |other| object has same ranges_ as |this| object's ranges_.
55 bool Equals(const BucketRanges* other) const;
57 private:
58 // A monotonically increasing list of values which determine which bucket to
59 // put a sample into. For each index, show the smallest sample that can be
60 // added to the corresponding bucket.
61 Ranges ranges_;
63 // Checksum for the conntents of ranges_. Used to detect random over-writes
64 // of our data, and to quickly see if some other BucketRanges instance is
65 // possibly Equal() to this instance.
66 // TODO(kaiwang): Consider change this to uint64. Because we see a lot of
67 // noise on UMA dashboard.
68 uint32 checksum_;
70 DISALLOW_COPY_AND_ASSIGN(BucketRanges);
73 //////////////////////////////////////////////////////////////////////////////
74 // Expose only for test.
75 BASE_EXPORT_PRIVATE extern const uint32 kCrcTable[256];
77 } // namespace base
79 #endif // BASE_METRICS_BUCKET_RANGES_H_