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/sample_vector.h" | 5 #include "base/metrics/sample_vector.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/bucket_ranges.h" | 8 #include "base/metrics/bucket_ranges.h" |
9 | 9 |
10 using std::vector; | 10 using std::vector; |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 | 13 |
14 typedef HistogramBase::Count Count; | 14 typedef HistogramBase::Count Count; |
15 typedef HistogramBase::Sample Sample; | 15 typedef HistogramBase::Sample Sample; |
16 | 16 |
17 SampleVector::SampleVector(const BucketRanges* bucket_ranges) | 17 SampleVector::SampleVector(const BucketRanges* bucket_ranges) |
18 : counts_(bucket_ranges->bucket_count()), | 18 : counts_(bucket_ranges->bucket_count()), |
19 bucket_ranges_(bucket_ranges) { | 19 bucket_ranges_(bucket_ranges) { |
20 CHECK_GE(bucket_ranges_->bucket_count(), 1u); | 20 CHECK_GE(bucket_ranges_->bucket_count(), 1u); |
21 } | 21 } |
22 | 22 |
23 SampleVector::~SampleVector() {} | 23 SampleVector::~SampleVector() {} |
24 | 24 |
25 void SampleVector::Accumulate(Sample value, Count count) { | 25 void SampleVector::Accumulate(Sample value, Count count) { |
26 size_t bucket_index = GetBucketIndex(value); | 26 size_t bucket_index = GetBucketIndex(value); |
27 counts_[bucket_index] += count; | 27 subtle::NoBarrier_Store(&counts_[bucket_index], |
| 28 subtle::NoBarrier_Load(&counts_[bucket_index]) + count); |
28 IncreaseSum(count * value); | 29 IncreaseSum(count * value); |
29 IncreaseRedundantCount(count); | 30 IncreaseRedundantCount(count); |
30 } | 31 } |
31 | 32 |
32 Count SampleVector::GetCount(Sample value) const { | 33 Count SampleVector::GetCount(Sample value) const { |
33 size_t bucket_index = GetBucketIndex(value); | 34 size_t bucket_index = GetBucketIndex(value); |
34 return counts_[bucket_index]; | 35 return counts_[bucket_index]; |
35 } | 36 } |
36 | 37 |
37 Count SampleVector::TotalCount() const { | 38 Count SampleVector::TotalCount() const { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 return; | 153 return; |
153 | 154 |
154 while (index_ < counts_->size()) { | 155 while (index_ < counts_->size()) { |
155 if ((*counts_)[index_] != 0) | 156 if ((*counts_)[index_] != 0) |
156 return; | 157 return; |
157 index_++; | 158 index_++; |
158 } | 159 } |
159 } | 160 } |
160 | 161 |
161 } // namespace base | 162 } // namespace base |
OLD | NEW |