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

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

Issue 2853853002: Fix overflow when logging MaxInt32 to a sparse histogram. (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | base/metrics/histogram_samples.cc » ('j') | base/metrics/persistent_sample_map.cc » ('J')
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 #ifndef BASE_METRICS_HISTOGRAM_SAMPLES_H_ 5 #ifndef BASE_METRICS_HISTOGRAM_SAMPLES_H_
6 #define BASE_METRICS_HISTOGRAM_SAMPLES_H_ 6 #define BASE_METRICS_HISTOGRAM_SAMPLES_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 191
192 class BASE_EXPORT SampleCountIterator { 192 class BASE_EXPORT SampleCountIterator {
193 public: 193 public:
194 virtual ~SampleCountIterator(); 194 virtual ~SampleCountIterator();
195 195
196 virtual bool Done() const = 0; 196 virtual bool Done() const = 0;
197 virtual void Next() = 0; 197 virtual void Next() = 0;
198 198
199 // Get the sample and count at current position. 199 // Get the sample and count at current position.
200 // |min| |max| and |count| can be NULL if the value is not of interest. 200 // |min| |max| and |count| can be NULL if the value is not of interest.
201 // Note: |max| is int64_t because histograms support logged values in the
202 // full int32_t range and bucket max is exclusive, so it needs to support
203 // values up to MAXINT32+1.
Ilya Sherman 2017/05/02 21:37:49 Could you add a compile-time assertion somewhere t
Alexei Svitkine (slow) 2017/05/03 15:21:53 Done.
201 // Requires: !Done(); 204 // Requires: !Done();
202 virtual void Get(HistogramBase::Sample* min, 205 virtual void Get(HistogramBase::Sample* min,
203 HistogramBase::Sample* max, 206 int64_t* max,
204 HistogramBase::Count* count) const = 0; 207 HistogramBase::Count* count) const = 0;
205 208
206 // Get the index of current histogram bucket. 209 // Get the index of current histogram bucket.
207 // For histograms that don't use predefined buckets, it returns false. 210 // For histograms that don't use predefined buckets, it returns false.
208 // Requires: !Done(); 211 // Requires: !Done();
209 virtual bool GetBucketIndex(size_t* index) const; 212 virtual bool GetBucketIndex(size_t* index) const;
210 }; 213 };
211 214
212 class BASE_EXPORT SingleSampleIterator : public SampleCountIterator { 215 class BASE_EXPORT SingleSampleIterator : public SampleCountIterator {
213 public: 216 public:
214 SingleSampleIterator(HistogramBase::Sample min, 217 SingleSampleIterator(HistogramBase::Sample min,
215 HistogramBase::Sample max, 218 int64_t max,
216 HistogramBase::Count count); 219 HistogramBase::Count count);
217 SingleSampleIterator(HistogramBase::Sample min, 220 SingleSampleIterator(HistogramBase::Sample min,
218 HistogramBase::Sample max, 221 int64_t max,
219 HistogramBase::Count count, 222 HistogramBase::Count count,
220 size_t bucket_index); 223 size_t bucket_index);
221 ~SingleSampleIterator() override; 224 ~SingleSampleIterator() override;
222 225
223 // SampleCountIterator: 226 // SampleCountIterator:
224 bool Done() const override; 227 bool Done() const override;
225 void Next() override; 228 void Next() override;
226 void Get(HistogramBase::Sample* min, 229 void Get(HistogramBase::Sample* min,
227 HistogramBase::Sample* max, 230 int64_t* max,
228 HistogramBase::Count* count) const override; 231 HistogramBase::Count* count) const override;
229 232
230 // SampleVector uses predefined buckets so iterator can return bucket index. 233 // SampleVector uses predefined buckets so iterator can return bucket index.
231 bool GetBucketIndex(size_t* index) const override; 234 bool GetBucketIndex(size_t* index) const override;
232 235
233 private: 236 private:
234 // Information about the single value to return. 237 // Information about the single value to return.
235 const HistogramBase::Sample min_; 238 const HistogramBase::Sample min_;
236 const HistogramBase::Sample max_; 239 const int64_t max_;
237 const size_t bucket_index_; 240 const size_t bucket_index_;
238 HistogramBase::Count count_; 241 HistogramBase::Count count_;
239 }; 242 };
240 243
241 } // namespace base 244 } // namespace base
242 245
243 #endif // BASE_METRICS_HISTOGRAM_SAMPLES_H_ 246 #endif // BASE_METRICS_HISTOGRAM_SAMPLES_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/histogram_samples.cc » ('j') | base/metrics/persistent_sample_map.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698