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

Unified Diff: base/metrics/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 side-by-side diff with in-line comments
Download patch
Index: base/metrics/histogram.cc
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc
index 7ff1b16184f10c9e54dd501b1b95a1f34fefc253..fb9ca9d4473d8e1c7b2811bcf3edae5c13c47e67 100644
--- a/base/metrics/histogram.cc
+++ b/base/metrics/histogram.cc
@@ -271,17 +271,28 @@ bool Histogram::HasConstructionArguments(Sample expected_minimum,
(expected_bucket_count == bucket_count()));
}
+int ClampValue(int value) {
Alexei Svitkine (slow) 2015/08/03 18:15:42 Put this in the anon namespace at the top of the f
amohammadkhan 2015/08/04 18:22:51 Done.
+ if (value > Histogram::kSampleType_MAX - 1)
+ return Histogram::kSampleType_MAX - 1;
+ if (value < 0)
+ return 0;
+ return value;
+}
+
void Histogram::Add(int value) {
+ AddCount(value, 1);
+}
+
+void Histogram::AddCount(int value, int count) {
DCHECK_EQ(0, ranges(0));
DCHECK_EQ(kSampleType_MAX, ranges(bucket_count()));
+ if (count < 0) {
Alexei Svitkine (slow) 2015/08/03 18:15:42 If the body is a single line, no need for {}'s.
amohammadkhan 2015/08/04 18:22:51 Done.
+ count = 0;
Alexei Svitkine (slow) 2015/08/03 18:15:42 Seems like a count of 0 would actually not change
amohammadkhan 2015/08/04 18:22:51 Done.
+ }
+ int clamped_value = ClampValue(value);
+ samples_->Accumulate(clamped_value, count);
- if (value > kSampleType_MAX - 1)
- value = kSampleType_MAX - 1;
- if (value < 0)
- value = 0;
- samples_->Accumulate(value, 1);
-
- FindAndRunCallback(value);
+ FindAndRunCallback(clamped_value);
}
scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const {

Powered by Google App Engine
This is Rietveld 408576698