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

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

Issue 23450016: Re-land https://codereview.chromium.org/23602005: Use nobarrier atomics for lossy counters in base:… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 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
« no previous file with comments | « base/metrics/histogram_samples.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « base/metrics/histogram_samples.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698