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

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

Issue 1618423004: Fix overflow bug in histogram sample data structures (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Rename tests, remove redundant comments. Created 4 years, 11 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/sample_map_unittest.cc ('k') | base/metrics/sample_vector_unittest.cc » ('j') | 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 namespace base { 10 namespace base {
(...skipping 25 matching lines...) Expand all
36 CHECK_LE(bucket_ranges_->bucket_count(), counts_size_); 36 CHECK_LE(bucket_ranges_->bucket_count(), counts_size_);
37 CHECK_GE(bucket_ranges_->bucket_count(), 1u); 37 CHECK_GE(bucket_ranges_->bucket_count(), 1u);
38 } 38 }
39 39
40 SampleVector::~SampleVector() {} 40 SampleVector::~SampleVector() {}
41 41
42 void SampleVector::Accumulate(Sample value, Count count) { 42 void SampleVector::Accumulate(Sample value, Count count) {
43 size_t bucket_index = GetBucketIndex(value); 43 size_t bucket_index = GetBucketIndex(value);
44 subtle::NoBarrier_Store(&counts_[bucket_index], 44 subtle::NoBarrier_Store(&counts_[bucket_index],
45 subtle::NoBarrier_Load(&counts_[bucket_index]) + count); 45 subtle::NoBarrier_Load(&counts_[bucket_index]) + count);
46 IncreaseSum(count * value); 46 IncreaseSum(static_cast<int64_t>(count) * value);
47 IncreaseRedundantCount(count); 47 IncreaseRedundantCount(count);
48 } 48 }
49 49
50 Count SampleVector::GetCount(Sample value) const { 50 Count SampleVector::GetCount(Sample value) const {
51 size_t bucket_index = GetBucketIndex(value); 51 size_t bucket_index = GetBucketIndex(value);
52 return subtle::NoBarrier_Load(&counts_[bucket_index]); 52 return subtle::NoBarrier_Load(&counts_[bucket_index]);
53 } 53 }
54 54
55 Count SampleVector::TotalCount() const { 55 Count SampleVector::TotalCount() const {
56 Count count = 0; 56 Count count = 0;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return; 187 return;
188 188
189 while (index_ < counts_size_) { 189 while (index_ < counts_size_) {
190 if (subtle::NoBarrier_Load(&counts_[index_]) != 0) 190 if (subtle::NoBarrier_Load(&counts_[index_]) != 0)
191 return; 191 return;
192 index_++; 192 index_++;
193 } 193 }
194 } 194 }
195 195
196 } // namespace base 196 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/sample_map_unittest.cc ('k') | base/metrics/sample_vector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698