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

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

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_samples.h ('k') | base/metrics/histogram_snapshot_manager.h » ('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 #include "base/metrics/histogram_samples.h"
6
7 #include "base/compiler_specific.h"
8 #include "base/pickle.h"
9
10 namespace base {
11
12 namespace {
13
14 class SampleCountPickleIterator : public SampleCountIterator {
15 public:
16 explicit SampleCountPickleIterator(PickleIterator* iter);
17
18 bool Done() const override;
19 void Next() override;
20 void Get(HistogramBase::Sample* min,
21 HistogramBase::Sample* max,
22 HistogramBase::Count* count) const override;
23
24 private:
25 PickleIterator* const iter_;
26
27 HistogramBase::Sample min_;
28 HistogramBase::Sample max_;
29 HistogramBase::Count count_;
30 bool is_done_;
31 };
32
33 SampleCountPickleIterator::SampleCountPickleIterator(PickleIterator* iter)
34 : iter_(iter),
35 is_done_(false) {
36 Next();
37 }
38
39 bool SampleCountPickleIterator::Done() const {
40 return is_done_;
41 }
42
43 void SampleCountPickleIterator::Next() {
44 DCHECK(!Done());
45 if (!iter_->ReadInt(&min_) ||
46 !iter_->ReadInt(&max_) ||
47 !iter_->ReadInt(&count_))
48 is_done_ = true;
49 }
50
51 void SampleCountPickleIterator::Get(HistogramBase::Sample* min,
52 HistogramBase::Sample* max,
53 HistogramBase::Count* count) const {
54 DCHECK(!Done());
55 *min = min_;
56 *max = max_;
57 *count = count_;
58 }
59
60 } // namespace
61
62 HistogramSamples::HistogramSamples() : sum_(0), redundant_count_(0) {}
63
64 HistogramSamples::~HistogramSamples() {}
65
66 void HistogramSamples::Add(const HistogramSamples& other) {
67 sum_ += other.sum();
68 HistogramBase::Count old_redundant_count =
69 subtle::NoBarrier_Load(&redundant_count_);
70 subtle::NoBarrier_Store(&redundant_count_,
71 old_redundant_count + other.redundant_count());
72 bool success = AddSubtractImpl(other.Iterator().get(), ADD);
73 DCHECK(success);
74 }
75
76 bool HistogramSamples::AddFromPickle(PickleIterator* iter) {
77 int64 sum;
78 HistogramBase::Count redundant_count;
79
80 if (!iter->ReadInt64(&sum) || !iter->ReadInt(&redundant_count))
81 return false;
82 sum_ += sum;
83 HistogramBase::Count old_redundant_count =
84 subtle::NoBarrier_Load(&redundant_count_);
85 subtle::NoBarrier_Store(&redundant_count_,
86 old_redundant_count + redundant_count);
87
88 SampleCountPickleIterator pickle_iter(iter);
89 return AddSubtractImpl(&pickle_iter, ADD);
90 }
91
92 void HistogramSamples::Subtract(const HistogramSamples& other) {
93 sum_ -= other.sum();
94 HistogramBase::Count old_redundant_count =
95 subtle::NoBarrier_Load(&redundant_count_);
96 subtle::NoBarrier_Store(&redundant_count_,
97 old_redundant_count - other.redundant_count());
98 bool success = AddSubtractImpl(other.Iterator().get(), SUBTRACT);
99 DCHECK(success);
100 }
101
102 bool HistogramSamples::Serialize(Pickle* pickle) const {
103 if (!pickle->WriteInt64(sum_) ||
104 !pickle->WriteInt(subtle::NoBarrier_Load(&redundant_count_)))
105 return false;
106
107 HistogramBase::Sample min;
108 HistogramBase::Sample max;
109 HistogramBase::Count count;
110 for (scoped_ptr<SampleCountIterator> it = Iterator();
111 !it->Done();
112 it->Next()) {
113 it->Get(&min, &max, &count);
114 if (!pickle->WriteInt(min) ||
115 !pickle->WriteInt(max) ||
116 !pickle->WriteInt(count))
117 return false;
118 }
119 return true;
120 }
121
122 void HistogramSamples::IncreaseSum(int64 diff) {
123 sum_ += diff;
124 }
125
126 void HistogramSamples::IncreaseRedundantCount(HistogramBase::Count diff) {
127 subtle::NoBarrier_Store(&redundant_count_,
128 subtle::NoBarrier_Load(&redundant_count_) + diff);
129 }
130
131 SampleCountIterator::~SampleCountIterator() {}
132
133 bool SampleCountIterator::GetBucketIndex(size_t* index) const {
134 DCHECK(!Done());
135 return false;
136 }
137
138 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_samples.h ('k') | base/metrics/histogram_snapshot_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698