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

Side by Side 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, 3 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef BASE_METRICS_HISTOGRAM_SAMPLES_H_
6 #define BASE_METRICS_HISTOGRAM_SAMPLES_H_
7
8 #include "base/basictypes.h"
9 #include "base/metrics/histogram_base.h"
10 #include "base/memory/scoped_ptr.h"
11
12 class Pickle;
13 class PickleIterator;
14
15 namespace base {
16
17 class SampleCountIterator;
18
19 // HistogramSamples is a container storing all samples of a histogram.
20 class BASE_EXPORT HistogramSamples {
21 public:
22 HistogramSamples();
23 virtual ~HistogramSamples();
24
25 virtual void Accumulate(HistogramBase::Sample value,
26 HistogramBase::Count count) = 0;
27 virtual HistogramBase::Count GetCount(HistogramBase::Sample value) const = 0;
28 virtual HistogramBase::Count TotalCount() const = 0;
29
30 virtual void Add(const HistogramSamples& other);
31
32 // Add from serialized samples.
33 virtual bool AddFromPickle(PickleIterator* iter);
34
35 virtual void Subtract(const HistogramSamples& other);
36
37 virtual scoped_ptr<SampleCountIterator> Iterator() const = 0;
38 virtual bool Serialize(Pickle* pickle) const;
39
40 // Accessor fuctions.
41 int64 sum() const { return sum_; }
42 HistogramBase::Count redundant_count() const { return redundant_count_; }
43
44 protected:
45 // Add/subtract sample counts data from the iterator.
46 // Add samples when |is_add| is true, else subtract samples.
47 virtual bool AddSubtractImpl(SampleCountIterator* iter, bool is_add) = 0;
Ilya Sherman 2012/08/29 23:41:27 Rather than passing a boolean parameter, please us
kaiwang 2012/08/30 03:13:22 As replied in earlier comment, I really don't see
Ilya Sherman 2012/08/30 07:57:40 The reason to use an enum rather than a boolean is
kaiwang 2012/09/07 01:14:11 Done.
48
49 void IncreaseSum(int64 diff);
Ilya Sherman 2012/08/29 23:41:27 Optional nit: Perhaps "IncreaseSumBy"?
50 void IncreaseRedundantCount(HistogramBase::Count diff);
51
52 private:
53 int64 sum_;
54
55 // |redundant_count_| helps identify memory corruption. It redundantly stores
56 // the total number of samples accumulated in the histogram. We can compare
57 // this count to the sum of the counts (TotalCount() function), and detect
58 // problems. Note, depending on the implementation of different histogram
59 // types, there might be races during histogram accumulation and snapshotting
60 // that we choose to accept. In this case, the tallies might mismatch even
61 // when no memory corruption has happened.
62 HistogramBase::Count redundant_count_;
63 };
64
65 class BASE_EXPORT SampleCountIterator {
66 public:
67 virtual ~SampleCountIterator();
68
69 virtual bool Done() const = 0;
70 virtual void Next() = 0;
71
72 // Get the sample and count at current position.
73 // |min| |max| and |count| can be NULL if the value is not of interest.
74 virtual void Get(HistogramBase::Sample* min,
75 HistogramBase::Sample* max,
76 HistogramBase::Count* count) const = 0;
77 };
78
79 } // namespace base
80
81 #endif // BASE_METRICS_HISTOGRAM_SAMPLES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698