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

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

Issue 1256363002: Add support to increase a UMA histogram bucket by an aribitrary integer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handling negative counts in sparse histograms. Created 5 years, 4 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/sparse_histogram.h" 5 #include "base/metrics/sparse_histogram.h"
6 6
7 #include "base/metrics/sample_map.h" 7 #include "base/metrics/sample_map.h"
8 #include "base/metrics/statistics_recorder.h" 8 #include "base/metrics/statistics_recorder.h"
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 28 matching lines...) Expand all
39 39
40 bool SparseHistogram::HasConstructionArguments( 40 bool SparseHistogram::HasConstructionArguments(
41 Sample expected_minimum, 41 Sample expected_minimum,
42 Sample expected_maximum, 42 Sample expected_maximum,
43 size_t expected_bucket_count) const { 43 size_t expected_bucket_count) const {
44 // SparseHistogram never has min/max/bucket_count limit. 44 // SparseHistogram never has min/max/bucket_count limit.
45 return false; 45 return false;
46 } 46 }
47 47
48 void SparseHistogram::Add(Sample value) { 48 void SparseHistogram::Add(Sample value) {
49 AddCount(value, 1);
50 }
51
52 void SparseHistogram::AddCount(Sample value, int count) {
49 { 53 {
50 base::AutoLock auto_lock(lock_); 54 base::AutoLock auto_lock(lock_);
51 samples_.Accumulate(value, 1); 55 if (count < 0) {
Alexei Svitkine (slow) 2015/08/03 18:15:42 Same comment as in the other method. This if can p
amohammadkhan 2015/08/04 18:22:51 Done.
56 count = 0;
57 }
58 samples_.Accumulate(value, count);
52 } 59 }
53
Alexei Svitkine (slow) 2015/08/03 18:15:42 Nit: Keep the empty line.
amohammadkhan 2015/08/04 18:22:51 Done.
54 FindAndRunCallback(value); 60 FindAndRunCallback(value);
55 } 61 }
56 62
57 scoped_ptr<HistogramSamples> SparseHistogram::SnapshotSamples() const { 63 scoped_ptr<HistogramSamples> SparseHistogram::SnapshotSamples() const {
58 scoped_ptr<SampleMap> snapshot(new SampleMap()); 64 scoped_ptr<SampleMap> snapshot(new SampleMap());
59 65
60 base::AutoLock auto_lock(lock_); 66 base::AutoLock auto_lock(lock_);
61 snapshot->Add(samples_); 67 snapshot->Add(samples_);
62 return snapshot.Pass(); 68 return snapshot.Pass();
63 } 69 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 std::string* output) const { 176 std::string* output) const {
171 StringAppendF(output, 177 StringAppendF(output,
172 "Histogram: %s recorded %d samples", 178 "Histogram: %s recorded %d samples",
173 histogram_name().c_str(), 179 histogram_name().c_str(),
174 total_count); 180 total_count);
175 if (flags() & ~kHexRangePrintingFlag) 181 if (flags() & ~kHexRangePrintingFlag)
176 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); 182 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag);
177 } 183 }
178 184
179 } // namespace base 185 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698