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_map.h" | 5 #include "base/metrics/sample_map.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } // namespace | 77 } // namespace |
78 | 78 |
79 SampleMap::SampleMap() : SampleMap(0) {} | 79 SampleMap::SampleMap() : SampleMap(0) {} |
80 | 80 |
81 SampleMap::SampleMap(uint64_t id) : HistogramSamples(id) {} | 81 SampleMap::SampleMap(uint64_t id) : HistogramSamples(id) {} |
82 | 82 |
83 SampleMap::~SampleMap() {} | 83 SampleMap::~SampleMap() {} |
84 | 84 |
85 void SampleMap::Accumulate(Sample value, Count count) { | 85 void SampleMap::Accumulate(Sample value, Count count) { |
86 sample_counts_[value] += count; | 86 sample_counts_[value] += count; |
87 IncreaseSum(static_cast<int64_t>(count) * value); | 87 IncreaseSumAndCount(static_cast<int64_t>(count) * value, count); |
88 IncreaseRedundantCount(count); | |
89 } | 88 } |
90 | 89 |
91 Count SampleMap::GetCount(Sample value) const { | 90 Count SampleMap::GetCount(Sample value) const { |
92 std::map<Sample, Count>::const_iterator it = sample_counts_.find(value); | 91 std::map<Sample, Count>::const_iterator it = sample_counts_.find(value); |
93 if (it == sample_counts_.end()) | 92 if (it == sample_counts_.end()) |
94 return 0; | 93 return 0; |
95 return it->second; | 94 return it->second; |
96 } | 95 } |
97 | 96 |
98 Count SampleMap::TotalCount() const { | 97 Count SampleMap::TotalCount() const { |
(...skipping 16 matching lines...) Expand all Loading... |
115 iter->Get(&min, &max, &count); | 114 iter->Get(&min, &max, &count); |
116 if (min + 1 != max) | 115 if (min + 1 != max) |
117 return false; // SparseHistogram only supports bucket with size 1. | 116 return false; // SparseHistogram only supports bucket with size 1. |
118 | 117 |
119 sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count; | 118 sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count; |
120 } | 119 } |
121 return true; | 120 return true; |
122 } | 121 } |
123 | 122 |
124 } // namespace base | 123 } // namespace base |
OLD | NEW |