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

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

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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/metrics/histogram_macros_unittest.cc ('k') | base/metrics/histogram_samples.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 namespace base {
13
14 class Pickle;
15 class PickleIterator;
16 class SampleCountIterator;
17
18 // HistogramSamples is a container storing all samples of a histogram.
19 class BASE_EXPORT HistogramSamples {
20 public:
21 HistogramSamples();
22 virtual ~HistogramSamples();
23
24 virtual void Accumulate(HistogramBase::Sample value,
25 HistogramBase::Count count) = 0;
26 virtual HistogramBase::Count GetCount(HistogramBase::Sample value) const = 0;
27 virtual HistogramBase::Count TotalCount() const = 0;
28
29 virtual void Add(const HistogramSamples& other);
30
31 // Add from serialized samples.
32 virtual bool AddFromPickle(PickleIterator* iter);
33
34 virtual void Subtract(const HistogramSamples& other);
35
36 virtual scoped_ptr<SampleCountIterator> Iterator() const = 0;
37 virtual bool Serialize(Pickle* pickle) const;
38
39 // Accessor fuctions.
40 int64 sum() const { return sum_; }
41 HistogramBase::Count redundant_count() const {
42 return subtle::NoBarrier_Load(&redundant_count_);
43 }
44
45 protected:
46 // Based on |op| type, add or subtract sample counts data from the iterator.
47 enum Operator { ADD, SUBTRACT };
48 virtual bool AddSubtractImpl(SampleCountIterator* iter, Operator op) = 0;
49
50 void IncreaseSum(int64 diff);
51 void IncreaseRedundantCount(HistogramBase::Count diff);
52
53 private:
54 int64 sum_;
55
56 // |redundant_count_| helps identify memory corruption. It redundantly stores
57 // the total number of samples accumulated in the histogram. We can compare
58 // this count to the sum of the counts (TotalCount() function), and detect
59 // problems. Note, depending on the implementation of different histogram
60 // types, there might be races during histogram accumulation and snapshotting
61 // that we choose to accept. In this case, the tallies might mismatch even
62 // when no memory corruption has happened.
63 HistogramBase::AtomicCount redundant_count_;
64 };
65
66 class BASE_EXPORT SampleCountIterator {
67 public:
68 virtual ~SampleCountIterator();
69
70 virtual bool Done() const = 0;
71 virtual void Next() = 0;
72
73 // Get the sample and count at current position.
74 // |min| |max| and |count| can be NULL if the value is not of interest.
75 // Requires: !Done();
76 virtual void Get(HistogramBase::Sample* min,
77 HistogramBase::Sample* max,
78 HistogramBase::Count* count) const = 0;
79
80 // Get the index of current histogram bucket.
81 // For histograms that don't use predefined buckets, it returns false.
82 // Requires: !Done();
83 virtual bool GetBucketIndex(size_t* index) const;
84 };
85
86 } // namespace base
87
88 #endif // BASE_METRICS_HISTOGRAM_SAMPLES_H_
OLDNEW
« no previous file with comments | « base/metrics/histogram_macros_unittest.cc ('k') | base/metrics/histogram_samples.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698