Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: base/metrics/bucket_ranges.h

Issue 1538743002: Switch to standard integer types in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DEPS roll too Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/message_loop/message_pump_win.cc ('k') | base/metrics/bucket_ranges.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
21 #include <stdint.h>
22
20 #include <vector> 23 #include <vector>
21 24
25 #include <limits.h>
26
22 #include "base/base_export.h" 27 #include "base/base_export.h"
23 #include "base/basictypes.h" 28 #include "base/macros.h"
24 #include "base/metrics/histogram_base.h" 29 #include "base/metrics/histogram_base.h"
25 30
26 namespace base { 31 namespace base {
27 32
28 class BASE_EXPORT BucketRanges { 33 class BASE_EXPORT BucketRanges {
29 public: 34 public:
30 typedef std::vector<HistogramBase::Sample> Ranges; 35 typedef std::vector<HistogramBase::Sample> Ranges;
31 36
32 explicit BucketRanges(size_t num_ranges); 37 explicit BucketRanges(size_t num_ranges);
33 ~BucketRanges(); 38 ~BucketRanges();
34 39
35 size_t size() const { return ranges_.size(); } 40 size_t size() const { return ranges_.size(); }
36 HistogramBase::Sample range(size_t i) const { return ranges_[i]; } 41 HistogramBase::Sample range(size_t i) const { return ranges_[i]; }
37 void set_range(size_t i, HistogramBase::Sample value); 42 void set_range(size_t i, HistogramBase::Sample value);
38 uint32 checksum() const { return checksum_; } 43 uint32_t checksum() const { return checksum_; }
39 void set_checksum(uint32 checksum) { checksum_ = checksum; } 44 void set_checksum(uint32_t checksum) { checksum_ = checksum; }
40 45
41 // A bucket is defined by a consecutive pair of entries in |ranges|, so there 46 // A bucket is defined by a consecutive pair of entries in |ranges|, so there
42 // is one fewer bucket than there are ranges. For example, if |ranges| is 47 // is one fewer bucket than there are ranges. For example, if |ranges| is
43 // [0, 1, 3, 7, INT_MAX], then the buckets in this histogram are 48 // [0, 1, 3, 7, INT_MAX], then the buckets in this histogram are
44 // [0, 1), [1, 3), [3, 7), and [7, INT_MAX). 49 // [0, 1), [1, 3), [3, 7), and [7, INT_MAX).
45 size_t bucket_count() const { return ranges_.size() - 1; } 50 size_t bucket_count() const { return ranges_.size() - 1; }
46 51
47 // Checksum methods to verify whether the ranges are corrupted (e.g. bad 52 // Checksum methods to verify whether the ranges are corrupted (e.g. bad
48 // memory access). 53 // memory access).
49 uint32 CalculateChecksum() const; 54 uint32_t CalculateChecksum() const;
50 bool HasValidChecksum() const; 55 bool HasValidChecksum() const;
51 void ResetChecksum(); 56 void ResetChecksum();
52 57
53 // Return true iff |other| object has same ranges_ as |this| object's ranges_. 58 // Return true iff |other| object has same ranges_ as |this| object's ranges_.
54 bool Equals(const BucketRanges* other) const; 59 bool Equals(const BucketRanges* other) const;
55 60
56 private: 61 private:
57 // A monotonically increasing list of values which determine which bucket to 62 // A monotonically increasing list of values which determine which bucket to
58 // put a sample into. For each index, show the smallest sample that can be 63 // put a sample into. For each index, show the smallest sample that can be
59 // added to the corresponding bucket. 64 // added to the corresponding bucket.
60 Ranges ranges_; 65 Ranges ranges_;
61 66
62 // Checksum for the conntents of ranges_. Used to detect random over-writes 67 // Checksum for the conntents of ranges_. Used to detect random over-writes
63 // of our data, and to quickly see if some other BucketRanges instance is 68 // of our data, and to quickly see if some other BucketRanges instance is
64 // possibly Equal() to this instance. 69 // possibly Equal() to this instance.
65 // TODO(kaiwang): Consider change this to uint64. Because we see a lot of 70 // TODO(kaiwang): Consider change this to uint64_t. Because we see a lot of
66 // noise on UMA dashboard. 71 // noise on UMA dashboard.
67 uint32 checksum_; 72 uint32_t checksum_;
68 73
69 DISALLOW_COPY_AND_ASSIGN(BucketRanges); 74 DISALLOW_COPY_AND_ASSIGN(BucketRanges);
70 }; 75 };
71 76
72 ////////////////////////////////////////////////////////////////////////////// 77 //////////////////////////////////////////////////////////////////////////////
73 // Expose only for test. 78 // Expose only for test.
74 BASE_EXPORT extern const uint32 kCrcTable[256]; 79 BASE_EXPORT extern const uint32_t kCrcTable[256];
75 80
76 } // namespace base 81 } // namespace base
77 82
78 #endif // BASE_METRICS_BUCKET_RANGES_H_ 83 #endif // BASE_METRICS_BUCKET_RANGES_H_
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_win.cc ('k') | base/metrics/bucket_ranges.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698