OLD | NEW |
(Empty) | |
| 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 |
| 13 // |
| 14 // TODO(kaiwang): Currently we keep all negative values in 0~1 bucket. Consider |
| 15 // changing 0 to INT_MIN. |
| 16 |
| 17 #ifndef BASE_METRICS_BUCKET_RANGES_H_ |
| 18 #define BASE_METRICS_BUCKET_RANGES_H_ |
| 19 |
| 20 #include <vector> |
| 21 |
| 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" |
| 26 |
| 27 namespace base { |
| 28 |
| 29 class BASE_EXPORT_PRIVATE BucketRanges { |
| 30 public: |
| 31 typedef std::vector<HistogramBase::Sample> Ranges; |
| 32 |
| 33 BucketRanges(size_t num_ranges); |
| 34 ~BucketRanges(); |
| 35 |
| 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; } |
| 41 |
| 42 // Checksum methods to verify whether the ranges are corrupted (e.g. bad |
| 43 // memory access). |
| 44 uint32 CalculateChecksum(); |
| 45 bool HasValidChecksum(); |
| 46 void ResetChecksum(); |
| 47 |
| 48 // Return true iff |other| object has same ranges_ as |this| object's ranges_. |
| 49 bool Equals(const BucketRanges* other) const; |
| 50 |
| 51 private: |
| 52 // A monotonically increasing list of values which determine which bucket to |
| 53 // put a sample into. For each index, show the smallest sample that can be |
| 54 // added to the corresponding bucket. |
| 55 Ranges ranges_; |
| 56 |
| 57 // Checksum for the conntents of ranges_. Used to detect random over-writes |
| 58 // of our data, and to quickly see if some other BucketRanges instance is |
| 59 // possibly Equal() to this instance. |
| 60 // TODO(kaiwang): Consider change this to uint64. Because we see a lot of |
| 61 // noise on UMA dashboard. |
| 62 uint32 checksum_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(BucketRanges); |
| 65 }; |
| 66 |
| 67 } // namespace base |
| 68 |
| 69 #endif // BASE_METRICS_BUCKET_RANGES_H_ |
OLD | NEW |