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/stl_util.h" | 9 #include "base/stl_util.h" |
9 | 10 |
10 namespace base { | 11 namespace base { |
11 | 12 |
12 typedef HistogramBase::Count Count; | 13 typedef HistogramBase::Count Count; |
13 typedef HistogramBase::Sample Sample; | 14 typedef HistogramBase::Sample Sample; |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // An iterator for going through a SampleMap. The logic here is identical | 18 // An iterator for going through a SampleMap. The logic here is identical |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 96 } |
96 | 97 |
97 Count SampleMap::TotalCount() const { | 98 Count SampleMap::TotalCount() const { |
98 Count count = 0; | 99 Count count = 0; |
99 for (const auto& entry : sample_counts_) { | 100 for (const auto& entry : sample_counts_) { |
100 count += entry.second; | 101 count += entry.second; |
101 } | 102 } |
102 return count; | 103 return count; |
103 } | 104 } |
104 | 105 |
105 scoped_ptr<SampleCountIterator> SampleMap::Iterator() const { | 106 std::unique_ptr<SampleCountIterator> SampleMap::Iterator() const { |
106 return make_scoped_ptr(new SampleMapIterator(sample_counts_)); | 107 return WrapUnique(new SampleMapIterator(sample_counts_)); |
107 } | 108 } |
108 | 109 |
109 bool SampleMap::AddSubtractImpl(SampleCountIterator* iter, Operator op) { | 110 bool SampleMap::AddSubtractImpl(SampleCountIterator* iter, Operator op) { |
110 Sample min; | 111 Sample min; |
111 Sample max; | 112 Sample max; |
112 Count count; | 113 Count count; |
113 for (; !iter->Done(); iter->Next()) { | 114 for (; !iter->Done(); iter->Next()) { |
114 iter->Get(&min, &max, &count); | 115 iter->Get(&min, &max, &count); |
115 if (min + 1 != max) | 116 if (min + 1 != max) |
116 return false; // SparseHistogram only supports bucket with size 1. | 117 return false; // SparseHistogram only supports bucket with size 1. |
117 | 118 |
118 sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count; | 119 sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count; |
119 } | 120 } |
120 return true; | 121 return true; |
121 } | 122 } |
122 | 123 |
123 } // namespace base | 124 } // namespace base |
OLD | NEW |