OLD | NEW |
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 #include "base/metrics/histogram_samples.h" | 5 #include "base/metrics/histogram_samples.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 HistogramSamples::HistogramSamples() : sum_(0), redundant_count_(0) {} | 61 HistogramSamples::HistogramSamples() : sum_(0), redundant_count_(0) {} |
62 | 62 |
63 HistogramSamples::~HistogramSamples() {} | 63 HistogramSamples::~HistogramSamples() {} |
64 | 64 |
65 void HistogramSamples::Add(const HistogramSamples& other) { | 65 void HistogramSamples::Add(const HistogramSamples& other) { |
66 sum_ += other.sum(); | 66 sum_ += other.sum(); |
67 redundant_count_ += other.redundant_count(); | 67 HistogramBase::Count old_redundant_count = |
| 68 subtle::NoBarrier_Load(&redundant_count_); |
| 69 subtle::NoBarrier_Store(&redundant_count_, |
| 70 old_redundant_count + other.redundant_count()); |
68 bool success = AddSubtractImpl(other.Iterator().get(), ADD); | 71 bool success = AddSubtractImpl(other.Iterator().get(), ADD); |
69 DCHECK(success); | 72 DCHECK(success); |
70 } | 73 } |
71 | 74 |
72 bool HistogramSamples::AddFromPickle(PickleIterator* iter) { | 75 bool HistogramSamples::AddFromPickle(PickleIterator* iter) { |
73 int64 sum; | 76 int64 sum; |
74 HistogramBase::Count redundant_count; | 77 HistogramBase::Count redundant_count; |
75 | 78 |
76 if (!iter->ReadInt64(&sum) || !iter->ReadInt(&redundant_count)) | 79 if (!iter->ReadInt64(&sum) || !iter->ReadInt(&redundant_count)) |
77 return false; | 80 return false; |
78 sum_ += sum; | 81 sum_ += sum; |
79 redundant_count_ += redundant_count; | 82 HistogramBase::Count old_redundant_count = |
| 83 subtle::NoBarrier_Load(&redundant_count_); |
| 84 subtle::NoBarrier_Store(&redundant_count_, |
| 85 old_redundant_count + redundant_count); |
80 | 86 |
81 SampleCountPickleIterator pickle_iter(iter); | 87 SampleCountPickleIterator pickle_iter(iter); |
82 return AddSubtractImpl(&pickle_iter, ADD); | 88 return AddSubtractImpl(&pickle_iter, ADD); |
83 } | 89 } |
84 | 90 |
85 void HistogramSamples::Subtract(const HistogramSamples& other) { | 91 void HistogramSamples::Subtract(const HistogramSamples& other) { |
86 sum_ -= other.sum(); | 92 sum_ -= other.sum(); |
87 redundant_count_ -= other.redundant_count(); | 93 HistogramBase::Count old_redundant_count = |
| 94 subtle::NoBarrier_Load(&redundant_count_); |
| 95 subtle::NoBarrier_Store(&redundant_count_, |
| 96 old_redundant_count - other.redundant_count()); |
88 bool success = AddSubtractImpl(other.Iterator().get(), SUBTRACT); | 97 bool success = AddSubtractImpl(other.Iterator().get(), SUBTRACT); |
89 DCHECK(success); | 98 DCHECK(success); |
90 } | 99 } |
91 | 100 |
92 bool HistogramSamples::Serialize(Pickle* pickle) const { | 101 bool HistogramSamples::Serialize(Pickle* pickle) const { |
93 if (!pickle->WriteInt64(sum_) || !pickle->WriteInt(redundant_count_)) | 102 if (!pickle->WriteInt64(sum_) || |
| 103 !pickle->WriteInt(subtle::NoBarrier_Load(&redundant_count_))) |
94 return false; | 104 return false; |
95 | 105 |
96 HistogramBase::Sample min; | 106 HistogramBase::Sample min; |
97 HistogramBase::Sample max; | 107 HistogramBase::Sample max; |
98 HistogramBase::Count count; | 108 HistogramBase::Count count; |
99 for (scoped_ptr<SampleCountIterator> it = Iterator(); | 109 for (scoped_ptr<SampleCountIterator> it = Iterator(); |
100 !it->Done(); | 110 !it->Done(); |
101 it->Next()) { | 111 it->Next()) { |
102 it->Get(&min, &max, &count); | 112 it->Get(&min, &max, &count); |
103 if (!pickle->WriteInt(min) || | 113 if (!pickle->WriteInt(min) || |
104 !pickle->WriteInt(max) || | 114 !pickle->WriteInt(max) || |
105 !pickle->WriteInt(count)) | 115 !pickle->WriteInt(count)) |
106 return false; | 116 return false; |
107 } | 117 } |
108 return true; | 118 return true; |
109 } | 119 } |
110 | 120 |
111 void HistogramSamples::IncreaseSum(int64 diff) { | 121 void HistogramSamples::IncreaseSum(int64 diff) { |
112 sum_ += diff; | 122 sum_ += diff; |
113 } | 123 } |
114 | 124 |
115 void HistogramSamples::IncreaseRedundantCount(HistogramBase::Count diff) { | 125 void HistogramSamples::IncreaseRedundantCount(HistogramBase::Count diff) { |
116 base::subtle::NoBarrier_Store(&redundant_count_, | 126 subtle::NoBarrier_Store(&redundant_count_, |
117 base::subtle::NoBarrier_Load(&redundant_count_) + diff); | 127 subtle::NoBarrier_Load(&redundant_count_) + diff); |
118 } | 128 } |
119 | 129 |
120 SampleCountIterator::~SampleCountIterator() {} | 130 SampleCountIterator::~SampleCountIterator() {} |
121 | 131 |
122 bool SampleCountIterator::GetBucketIndex(size_t* index) const { | 132 bool SampleCountIterator::GetBucketIndex(size_t* index) const { |
123 DCHECK(!Done()); | 133 DCHECK(!Done()); |
124 return false; | 134 return false; |
125 } | 135 } |
126 | 136 |
127 } // namespace base | 137 } // namespace base |
OLD | NEW |