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

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

Issue 1618423004: Fix overflow bug in histogram sample data structures (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: 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
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_map.h" 5 #include "base/metrics/sample_map.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace base { 9 namespace base {
10 10
11 typedef HistogramBase::Count Count; 11 typedef HistogramBase::Count Count;
12 typedef HistogramBase::Sample Sample; 12 typedef HistogramBase::Sample Sample;
13 13
14 SampleMap::SampleMap() : SampleMap(0) {} 14 SampleMap::SampleMap() : SampleMap(0) {}
15 15
16 SampleMap::SampleMap(uint64_t id) : HistogramSamples(id) {} 16 SampleMap::SampleMap(uint64_t id) : HistogramSamples(id) {}
17 17
18 SampleMap::~SampleMap() {} 18 SampleMap::~SampleMap() {}
19 19
20 void SampleMap::Accumulate(Sample value, Count count) { 20 void SampleMap::Accumulate(Sample value, Count count) {
21 sample_counts_[value] += count; 21 sample_counts_[value] += count;
22 IncreaseSum(count * value); 22 IncreaseSum(static_cast<int64_t>(count) * value);
23 IncreaseRedundantCount(count); 23 IncreaseRedundantCount(count);
24 } 24 }
25 25
26 Count SampleMap::GetCount(Sample value) const { 26 Count SampleMap::GetCount(Sample value) const {
27 std::map<Sample, Count>::const_iterator it = sample_counts_.find(value); 27 std::map<Sample, Count>::const_iterator it = sample_counts_.find(value);
28 if (it == sample_counts_.end()) 28 if (it == sample_counts_.end())
29 return 0; 29 return 0;
30 return it->second; 30 return it->second;
31 } 31 }
32 32
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 *count = iter_->second; 85 *count = iter_->second;
86 } 86 }
87 87
88 void SampleMapIterator::SkipEmptyBuckets() { 88 void SampleMapIterator::SkipEmptyBuckets() {
89 while (!Done() && iter_->second == 0) { 89 while (!Done() && iter_->second == 0) {
90 ++iter_; 90 ++iter_;
91 } 91 }
92 } 92 }
93 93
94 } // namespace base 94 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698