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

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

Issue 2867303004: [histogram] Make histograms more resistant to overflows. (Closed)
Patch Set: final final fix 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.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 // Histogram is an object that aggregates statistics, and can summarize them in 5 // Histogram is an object that aggregates statistics, and can summarize them in
6 // various forms, including ASCII graphical, HTML, and numerically (as a 6 // various forms, including ASCII graphical, HTML, and numerically (as a
7 // vector of numbers corresponding to each of the aggregating buckets). 7 // vector of numbers corresponding to each of the aggregating buckets).
8 8
9 // It supports calls to accumulate either time intervals (which are processed 9 // It supports calls to accumulate either time intervals (which are processed
10 // as integral number of milliseconds), or arbitrary integral units. 10 // as integral number of milliseconds), or arbitrary integral units.
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketPlacementTest); 257 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketPlacementTest);
258 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); 258 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts);
259 259
260 friend class StatisticsRecorder; // To allow it to delete duplicates. 260 friend class StatisticsRecorder; // To allow it to delete duplicates.
261 friend class StatisticsRecorderTest; 261 friend class StatisticsRecorderTest;
262 262
263 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 263 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
264 base::PickleIterator* iter); 264 base::PickleIterator* iter);
265 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 265 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
266 266
267 // Implementation of SnapshotSamples function. 267 // Create a snapshot containing all samples (both logged and unlogged).
268 std::unique_ptr<SampleVector> SnapshotSampleVector() const; 268 // Implementation of SnapshotSamples method with a more specific type for
269 // internal use.
270 std::unique_ptr<SampleVector> SnapshotAllSamples() const;
271
272 // Create a copy of unlogged samples.
273 std::unique_ptr<SampleVector> SnapshotUnloggedSamples() const;
269 274
270 //---------------------------------------------------------------------------- 275 //----------------------------------------------------------------------------
271 // Helpers for emitting Ascii graphic. Each method appends data to output. 276 // Helpers for emitting Ascii graphic. Each method appends data to output.
272 277
273 void WriteAsciiImpl(bool graph_it, 278 void WriteAsciiImpl(bool graph_it,
274 const std::string& newline, 279 const std::string& newline,
275 std::string* output) const; 280 std::string* output) const;
276 281
277 // Find out how large (graphically) the largest bucket will appear to be. 282 // Find out how large (graphically) the largest bucket will appear to be.
278 double GetPeakBucketSize(const SampleVectorBase& samples) const; 283 double GetPeakBucketSize(const SampleVectorBase& samples) const;
(...skipping 17 matching lines...) Expand all
296 void GetCountAndBucketData(Count* count, 301 void GetCountAndBucketData(Count* count,
297 int64_t* sum, 302 int64_t* sum,
298 ListValue* buckets) const override; 303 ListValue* buckets) const override;
299 304
300 // Does not own this object. Should get from StatisticsRecorder. 305 // Does not own this object. Should get from StatisticsRecorder.
301 const BucketRanges* bucket_ranges_; 306 const BucketRanges* bucket_ranges_;
302 307
303 Sample declared_min_; // Less than this goes into the first bucket. 308 Sample declared_min_; // Less than this goes into the first bucket.
304 Sample declared_max_; // Over this goes into the last bucket. 309 Sample declared_max_; // Over this goes into the last bucket.
305 310
306 // Finally, provide the state that changes with the addition of each new 311 // Samples that have not yet been logged with SnapshotDelta().
307 // sample. 312 std::unique_ptr<HistogramSamples> unlogged_samples_;
308 std::unique_ptr<SampleVectorBase> samples_;
309 313
310 // Also keep a previous uploaded state for calculating deltas. 314 // Accumulation of all samples that have been logged with SnapshotDelta().
311 std::unique_ptr<HistogramSamples> logged_samples_; 315 std::unique_ptr<HistogramSamples> logged_samples_;
312 316
313 // Flag to indicate if PrepareFinalDelta has been previously called. It is 317 // Flag to indicate if PrepareFinalDelta has been previously called. It is
314 // used to DCHECK that a final delta is not created multiple times. 318 // used to DCHECK that a final delta is not created multiple times.
315 mutable bool final_delta_created_ = false; 319 mutable bool final_delta_created_ = false;
316 320
317 DISALLOW_COPY_AND_ASSIGN(Histogram); 321 DISALLOW_COPY_AND_ASSIGN(Histogram);
318 }; 322 };
319 323
320 //------------------------------------------------------------------------------ 324 //------------------------------------------------------------------------------
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 539 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
536 540
537 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); 541 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges);
538 542
539 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); 543 DISALLOW_COPY_AND_ASSIGN(CustomHistogram);
540 }; 544 };
541 545
542 } // namespace base 546 } // namespace base
543 547
544 #endif // BASE_METRICS_HISTOGRAM_H_ 548 #endif // BASE_METRICS_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/histogram.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698