OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // BucketRanges stores the vector of ranges that delimit what samples are | 5 // BucketRanges stores the vector of ranges that delimit what samples are |
6 // tallied in the corresponding buckets of a histogram. Histograms that have | 6 // tallied in the corresponding buckets of a histogram. Histograms that have |
7 // same ranges for all their corresponding buckets should share the same | 7 // same ranges for all their corresponding buckets should share the same |
8 // BucketRanges object. | 8 // BucketRanges object. |
9 // | 9 // |
10 // E.g. A 5 buckets LinearHistogram with 1 as minimal value and 4 as maximal | 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: | 11 // value will need a BucketRanges with 6 ranges: |
12 // 0, 1, 2, 3, 4, INT_MAX | 12 // 0, 1, 2, 3, 4, INT_MAX |
13 // | 13 // |
14 // TODO(kaiwang): Currently we keep all negative values in 0~1 bucket. Consider | 14 // TODO(kaiwang): Currently we keep all negative values in 0~1 bucket. Consider |
15 // changing 0 to INT_MIN. | 15 // changing 0 to INT_MIN. |
16 | 16 |
17 #ifndef BASE_METRICS_BUCKET_RANGES_H_ | 17 #ifndef BASE_METRICS_BUCKET_RANGES_H_ |
18 #define BASE_METRICS_BUCKET_RANGES_H_ | 18 #define BASE_METRICS_BUCKET_RANGES_H_ |
19 | 19 |
20 #include <stddef.h> | 20 #include <stddef.h> |
21 #include <stdint.h> | 21 #include <stdint.h> |
22 | 22 |
23 #include <vector> | 23 #include <vector> |
24 | 24 |
25 #include <limits.h> | 25 #include <limits.h> |
26 | 26 |
| 27 #include "base/atomicops.h" |
27 #include "base/base_export.h" | 28 #include "base/base_export.h" |
28 #include "base/macros.h" | 29 #include "base/macros.h" |
29 #include "base/metrics/histogram_base.h" | 30 #include "base/metrics/histogram_base.h" |
30 | 31 |
31 namespace base { | 32 namespace base { |
32 | 33 |
33 class BASE_EXPORT BucketRanges { | 34 class BASE_EXPORT BucketRanges { |
34 public: | 35 public: |
35 typedef std::vector<HistogramBase::Sample> Ranges; | 36 typedef std::vector<HistogramBase::Sample> Ranges; |
36 | 37 |
(...skipping 14 matching lines...) Expand all Loading... |
51 | 52 |
52 // Checksum methods to verify whether the ranges are corrupted (e.g. bad | 53 // Checksum methods to verify whether the ranges are corrupted (e.g. bad |
53 // memory access). | 54 // memory access). |
54 uint32_t CalculateChecksum() const; | 55 uint32_t CalculateChecksum() const; |
55 bool HasValidChecksum() const; | 56 bool HasValidChecksum() const; |
56 void ResetChecksum(); | 57 void ResetChecksum(); |
57 | 58 |
58 // Return true iff |other| object has same ranges_ as |this| object's ranges_. | 59 // Return true iff |other| object has same ranges_ as |this| object's ranges_. |
59 bool Equals(const BucketRanges* other) const; | 60 bool Equals(const BucketRanges* other) const; |
60 | 61 |
| 62 // Set and get a reference into persistent memory where this bucket data |
| 63 // can be found (and re-used). These calls are internally atomic with no |
| 64 // safety against overwriting an existing value since though it is wasteful |
| 65 // to have multiple identical persistent records, it is still safe. |
| 66 void set_persistent_reference(uint32_t ref) const { |
| 67 subtle::NoBarrier_Store(&persistent_reference_, ref); |
| 68 } |
| 69 uint32_t persistent_reference() const { |
| 70 return subtle::NoBarrier_Load(&persistent_reference_); |
| 71 } |
| 72 |
61 private: | 73 private: |
62 // A monotonically increasing list of values which determine which bucket to | 74 // A monotonically increasing list of values which determine which bucket to |
63 // put a sample into. For each index, show the smallest sample that can be | 75 // put a sample into. For each index, show the smallest sample that can be |
64 // added to the corresponding bucket. | 76 // added to the corresponding bucket. |
65 Ranges ranges_; | 77 Ranges ranges_; |
66 | 78 |
67 // Checksum for the conntents of ranges_. Used to detect random over-writes | 79 // Checksum for the conntents of ranges_. Used to detect random over-writes |
68 // of our data, and to quickly see if some other BucketRanges instance is | 80 // of our data, and to quickly see if some other BucketRanges instance is |
69 // possibly Equal() to this instance. | 81 // possibly Equal() to this instance. |
70 // TODO(kaiwang): Consider change this to uint64_t. Because we see a lot of | 82 // TODO(kaiwang): Consider change this to uint64_t. Because we see a lot of |
71 // noise on UMA dashboard. | 83 // noise on UMA dashboard. |
72 uint32_t checksum_; | 84 uint32_t checksum_; |
73 | 85 |
| 86 // A reference into a global PersistentMemoryAllocator where the ranges |
| 87 // information is stored. This allows for the record to be created once and |
| 88 // re-used simply by having all histograms with the same ranges use the |
| 89 // same reference. |
| 90 mutable subtle::Atomic32 persistent_reference_ = 0; |
| 91 |
74 DISALLOW_COPY_AND_ASSIGN(BucketRanges); | 92 DISALLOW_COPY_AND_ASSIGN(BucketRanges); |
75 }; | 93 }; |
76 | 94 |
77 ////////////////////////////////////////////////////////////////////////////// | 95 ////////////////////////////////////////////////////////////////////////////// |
78 // Expose only for test. | 96 // Expose only for test. |
79 BASE_EXPORT extern const uint32_t kCrcTable[256]; | 97 BASE_EXPORT extern const uint32_t kCrcTable[256]; |
80 | 98 |
81 } // namespace base | 99 } // namespace base |
82 | 100 |
83 #endif // BASE_METRICS_BUCKET_RANGES_H_ | 101 #endif // BASE_METRICS_BUCKET_RANGES_H_ |
OLD | NEW |