Bug 684091. Add the ability to subtract values from Histograms. r=taras
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Thu, 08 Sep 2011 14:05:06 -0400
changeset 76756 0f7583869bbd5f8cd4731f0d9f805a965fbe31a2
parent 76755 6d88b1cca4b370cca8f9532c560565dd5decd99b
child 76757 eb8a6747f6838df1df2a76f49b387beda68a90cf
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewerstaras
bugs684091
milestone9.0a1
Bug 684091. Add the ability to subtract values from Histograms. r=taras This is a copy of Add where we Accumulate with -1 instead of 1. I'm doing this as a copy instead of factoring out the common code to make this file easier to compare with chromium's histrogram.cc
ipc/chromium/src/base/histogram.cc
ipc/chromium/src/base/histogram.h
--- a/ipc/chromium/src/base/histogram.cc
+++ b/ipc/chromium/src/base/histogram.cc
@@ -125,16 +125,27 @@ void Histogram::Add(int value) {
   if (value < 0)
     value = 0;
   size_t index = BucketIndex(value);
   DCHECK_GE(value, ranges(index));
   DCHECK_LT(value, ranges(index + 1));
   Accumulate(value, 1, index);
 }
 
+void Histogram::Subtract(int value) {
+  if (value > kSampleType_MAX - 1)
+    value = kSampleType_MAX - 1;
+  if (value < 0)
+    value = 0;
+  size_t index = BucketIndex(value);
+  DCHECK_GE(value, ranges(index));
+  DCHECK_LT(value, ranges(index + 1));
+  Accumulate(value, -1, index);
+}
+
 void Histogram::AddBoolean(bool value) {
   DCHECK(false);
 }
 
 void Histogram::AddSampleSet(const SampleSet& sample) {
   sample_.Add(sample);
 }
 
--- a/ipc/chromium/src/base/histogram.h
+++ b/ipc/chromium/src/base/histogram.h
@@ -376,16 +376,17 @@ class Histogram {
                                Flags flags);
   static Histogram* FactoryTimeGet(const std::string& name,
                                    base::TimeDelta minimum,
                                    base::TimeDelta maximum,
                                    size_t bucket_count,
                                    Flags flags);
 
   void Add(int value);
+  void Subtract(int value);
 
   // This method is an interface, used only by BooleanHistogram.
   virtual void AddBoolean(bool value);
 
   // Accept a TimeDelta to increment.
   void AddTime(TimeDelta time) {
     Add(static_cast<int>(time.InMilliseconds()));
   }