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

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

Issue 2644143006: Report reasons for a negative histogram sample count. (Closed)
Patch Set: Created 3 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/persistent_sample_map.h" 5 #include "base/metrics/persistent_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/metrics/histogram_macros.h"
9 #include "base/metrics/persistent_histogram_allocator.h" 10 #include "base/metrics/persistent_histogram_allocator.h"
10 #include "base/stl_util.h" 11 #include "base/stl_util.h"
11 12
12 namespace base { 13 namespace base {
13 14
14 typedef HistogramBase::Count Count; 15 typedef HistogramBase::Count Count;
15 typedef HistogramBase::Sample Sample; 16 typedef HistogramBase::Sample Sample;
16 17
17 namespace { 18 namespace {
18 19
20 enum NegativeSampleReason {
21 NOT_NEGATIVE,
Alexei Svitkine (slow) 2017/01/20 19:11:30 Since you're never logging this, suggest just remo
bcwhite 2017/01/20 19:17:06 I use it as a default value in order to be able se
Alexei Svitkine (slow) 2017/01/20 19:21:30 Right, I am suggesting you could use MAX_NEGATIVE_
bcwhite 2017/01/20 19:59:19 Done.
22 PERSISTENT_SPARSE_HAVE_LOGGED_BUT_NOT_SAMPLE,
23 PERSISTENT_SPARSE_SAMPLE_LESS_THAN_LOGGED,
24 MAX_NEGATIVE_SAMPLE_REASONS
25 };
26
19 // An iterator for going through a PersistentSampleMap. The logic here is 27 // An iterator for going through a PersistentSampleMap. The logic here is
20 // identical to that of SampleMapIterator but with different data structures. 28 // identical to that of SampleMapIterator but with different data structures.
21 // Changes here likely need to be duplicated there. 29 // Changes here likely need to be duplicated there.
22 class PersistentSampleMapIterator : public SampleCountIterator { 30 class PersistentSampleMapIterator : public SampleCountIterator {
23 public: 31 public:
24 typedef std::map<HistogramBase::Sample, HistogramBase::Count*> 32 typedef std::map<HistogramBase::Sample, HistogramBase::Count*>
25 SampleToCountMap; 33 SampleToCountMap;
26 34
27 explicit PersistentSampleMapIterator(const SampleToCountMap& sample_counts); 35 explicit PersistentSampleMapIterator(const SampleToCountMap& sample_counts);
28 ~PersistentSampleMapIterator() override; 36 ~PersistentSampleMapIterator() override;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return ref; 182 return ref;
175 } 183 }
176 184
177 bool PersistentSampleMap::AddSubtractImpl(SampleCountIterator* iter, 185 bool PersistentSampleMap::AddSubtractImpl(SampleCountIterator* iter,
178 Operator op) { 186 Operator op) {
179 Sample min; 187 Sample min;
180 Sample max; 188 Sample max;
181 Count count; 189 Count count;
182 for (; !iter->Done(); iter->Next()) { 190 for (; !iter->Done(); iter->Next()) {
183 iter->Get(&min, &max, &count); 191 iter->Get(&min, &max, &count);
192 if (count == 0)
193 continue;
184 if (min + 1 != max) 194 if (min + 1 != max)
185 return false; // SparseHistogram only supports bucket with size 1. 195 return false; // SparseHistogram only supports bucket with size 1.
186 196
197 #if 0 // TODO(bcwhite) Re-enable efficient version after crbug.com/682680.
187 *GetOrCreateSampleCountStorage(min) += 198 *GetOrCreateSampleCountStorage(min) +=
188 (op == HistogramSamples::ADD) ? count : -count; 199 (op == HistogramSamples::ADD) ? count : -count;
200 #else
201 if (op == HistogramSamples::ADD) {
202 *GetOrCreateSampleCountStorage(min) += count;
203 } else {
204 // Subtract is used only for determining deltas when reporting which
205 // means that it's in the "logged" iterator. It should have an active
206 // sample record and thus there is no need to try to create one.
207 NegativeSampleReason reason = NOT_NEGATIVE;
208 Count* bucket = GetSampleCountStorage(min);
209 if (bucket == nullptr) {
210 reason = PERSISTENT_SPARSE_HAVE_LOGGED_BUT_NOT_SAMPLE;
211 } else {
212 if (*bucket < count) {
213 reason = PERSISTENT_SPARSE_SAMPLE_LESS_THAN_LOGGED;
214 *bucket = 0;
Alexei Svitkine (slow) 2017/01/20 19:11:30 This is also changing behavior - right? Seems it
bcwhite 2017/01/20 19:17:06 Correct. The benefit this way is that we'll know
Alexei Svitkine (slow) 2017/01/20 19:21:30 OK.
215 } else {
216 *bucket -= count;
217 }
218 }
219 if (reason != NOT_NEGATIVE) {
220 UMA_HISTOGRAM_ENUMERATION("UMA.NegativeSamples.Reason", reason,
221 MAX_NEGATIVE_SAMPLE_REASONS);
222 }
223 }
224 #endif
189 } 225 }
190 return true; 226 return true;
191 } 227 }
192 228
193 Count* PersistentSampleMap::GetSampleCountStorage(Sample value) { 229 Count* PersistentSampleMap::GetSampleCountStorage(Sample value) {
194 // If |value| is already in the map, just return that. 230 // If |value| is already in the map, just return that.
195 auto it = sample_counts_.find(value); 231 auto it = sample_counts_.find(value);
196 if (it != sample_counts_.end()) 232 if (it != sample_counts_.end())
197 return it->second; 233 return it->second;
198 234
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 found_count = &record->count; 313 found_count = &record->count;
278 if (!import_everything) 314 if (!import_everything)
279 break; 315 break;
280 } 316 }
281 } 317 }
282 318
283 return found_count; 319 return found_count;
284 } 320 }
285 321
286 } // namespace base 322 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698