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

Unified Diff: base/metrics/histogram_samples.h

Issue 10829466: SampleSet -> HistogramSamples (will be reused by SparseHistogram) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: base/metrics/histogram_samples.h
===================================================================
--- base/metrics/histogram_samples.h (revision 0)
+++ base/metrics/histogram_samples.h (revision 0)
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_METRICS_HISTOGRAM_SAMPLES_H_
+#define BASE_METRICS_HISTOGRAM_SAMPLES_H_
+
+#include "base/basictypes.h"
+#include "base/metrics/histogram_base.h"
+#include "base/memory/scoped_ptr.h"
+
+class Pickle;
+class PickleIterator;
+
+namespace base {
+
+class SampleCountIterator;
+
+// HistogramSamples is a container storing all samples of a histogram.
+class BASE_EXPORT HistogramSamples {
+ public:
+ HistogramSamples();
+ virtual ~HistogramSamples();
+
+ virtual void Accumulate(HistogramBase::Sample value,
+ HistogramBase::Count count) = 0;
+ virtual HistogramBase::Count GetCount(HistogramBase::Sample value) const = 0;
+ virtual HistogramBase::Count TotalCount() const = 0;
+
+ virtual void Add(const HistogramSamples& other);
+
+ // Add from serialized samples.
+ virtual bool AddFromPickle(PickleIterator* iter);
+
+ virtual void Subtract(const HistogramSamples& other);
+
+ virtual scoped_ptr<SampleCountIterator> Iterator() const = 0;
+ virtual bool Serialize(Pickle* pickle) const;
+
+ // Accessor fuctions.
+ int64 sum() const { return sum_; }
+ HistogramBase::Count redundant_count() const { return redundant_count_; }
+
+ protected:
+ // Add/subtract sample counts data from the iterator.
+ virtual bool AddSubtractImpl(SampleCountIterator* iter, bool is_add) = 0;
+
+ void set_sum(int64 sum) { sum_ = sum; }
+ void set_redundant_count(HistogramBase::Count redundant_count) {
+ redundant_count_ = redundant_count;
+ }
+
+ private:
+ int64 sum_;
+
+ // |redundant_count_| helps identify memory corruption. It redundantly stores
+ // the total number of samples accumulated in the histogram. We can compare
+ // this count to the sum of the counts (TotalCount() function), and detect
+ // problems. Note, depending on the implementation of different histogram
+ // types, there might be races during histogram accumulation and snapshotting
+ // that we choose to accept. In this case, the tallies might mismatch even
+ // when no memory corruption has happened.
+ HistogramBase::Count redundant_count_;
+};
+
+class BASE_EXPORT SampleCountIterator {
+ public:
+ virtual ~SampleCountIterator();
+
+ virtual bool Done() = 0;
Ilya Sherman 2012/08/29 08:48:16 nit: const?
kaiwang 2012/08/29 22:42:16 Done.
+ virtual void Next() = 0;
+
+ // Get the sample and count at current position.
+ // |min| |max| and |count| can be NULL if the value is not interested.
Ilya Sherman 2012/08/29 08:48:16 nit: "interested" -> "of interest"
kaiwang 2012/08/29 22:42:16 Done.
+ virtual void Get(HistogramBase::Sample* min,
+ HistogramBase::Sample* max,
+ HistogramBase::Count* count) = 0;
Ilya Sherman 2012/08/29 08:48:16 nit: const?
kaiwang 2012/08/29 22:42:16 Done.
+};
+
+} // namespace base
+
+#endif // BASE_METRICS_HISTOGRAM_SAMPLES_H_
Property changes on: base/metrics/histogram_samples.h
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698