Bug 837271 - part 1 - add means to control computation of extended statistics to histogram code; r=vladan
authorNathan Froyd <froydnj@mozilla.com>
Wed, 13 Feb 2013 10:31:25 -0500
changeset 131924 6553a0cac0af08d4f420d77ad2b27d8393e1a261
parent 131923 edeee46d8c733d24f2c7a0629372eef446bb352e
child 131925 f22ec99b6a766bc838c46a0a8ad5b2e3ef284b5d
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladan
bugs837271
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 837271 - part 1 - add means to control computation of extended statistics to histogram code; r=vladan
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
@@ -554,17 +554,18 @@ const std::string Histogram::GetAsciiBuc
   else
     StringAppendF(&result, "%d", ranges(i));
   return result;
 }
 
 // Update histogram data with new sample.
 void Histogram::Accumulate(Sample value, Count count, size_t index) {
   // Note locking not done in this version!!!
-  sample_.AccumulateWithExponentialStats(value, count, index);
+  sample_.AccumulateWithExponentialStats(value, count, index,
+					 flags_ & kExtendedStatisticsFlag);
 }
 
 void Histogram::SetBucketRange(size_t i, Sample value) {
   DCHECK_GT(bucket_count_, i);
   ranges_[i] = value;
 }
 
 bool Histogram::ValidateBucketRanges() const {
@@ -738,22 +739,25 @@ void Histogram::SampleSet::AccumulateWit
                                                      Count count,
                                                      size_t index) {
   Accumulate(value, count, index);
   sum_squares_ += static_cast<int64_t>(count) * value * value;
 }
 
 void Histogram::SampleSet::AccumulateWithExponentialStats(Sample value,
                                                           Count count,
-                                                          size_t index) {
+                                                          size_t index,
+							  bool computeExtendedStatistics) {
   Accumulate(value, count, index);
-  DCHECK_GE(value, 0);
-  float value_log = logf(static_cast<float>(value) + 1.0f);
-  log_sum_ += count * value_log;
-  log_sum_squares_ += count * value_log * value_log;
+  if (computeExtendedStatistics) {
+    DCHECK_GE(value, 0);
+    float value_log = logf(static_cast<float>(value) + 1.0f);
+    log_sum_ += count * value_log;
+    log_sum_squares_ += count * value_log * value_log;
+  }
 }
 
 Count Histogram::SampleSet::TotalCount() const {
   Count total = 0;
   for (Counts::const_iterator it = counts_.begin();
        it != counts_.end();
        ++it) {
     total += *it;
--- a/ipc/chromium/src/base/histogram.h
+++ b/ipc/chromium/src/base/histogram.h
@@ -285,16 +285,17 @@ class Histogram {
     EXPONENTIAL,
     LINEAR,
     CUSTOM
   };
 
   enum Flags {
     kNoFlags = 0,
     kUmaTargetedHistogramFlag = 0x1,  // Histogram should be UMA uploaded.
+    kExtendedStatisticsFlag = 0x2, // OK to gather extended statistics on histograms.
 
     // Indicate that the histogram was pickled to be sent across an IPC Channel.
     // If we observe this flag on a histogram being aggregated into after IPC,
     // then we are running in a single process mode, and the aggregation should
     // not take place (as we would be aggregating back into the source
     // histogram!).
     kIPCSerializationSourceFlag = 0x10,
 
@@ -331,17 +332,19 @@ class Histogram {
 
     // Adjust size of counts_ for use with given histogram.
     void Resize(const Histogram& histogram);
     void CheckSize(const Histogram& histogram) const;
 
     // Accessor for histogram to make routine additions.
     void AccumulateWithLinearStats(Sample value, Count count, size_t index);
     // Alternate routine for exponential histograms.
-    void AccumulateWithExponentialStats(Sample value, Count count, size_t index);
+    // computeExpensiveStatistics should be true if we want to compute log sums.
+    void AccumulateWithExponentialStats(Sample value, Count count, size_t index,
+					bool computeExtendedStatistics);
 
     // Accessor methods.
     Count counts(size_t i) const { return counts_[i]; }
     Count TotalCount() const;
     int64_t sum() const { return sum_; }
     uint64_t sum_squares() const { return sum_squares_; }
     double log_sum() const { return log_sum_; }
     double log_sum_squares() const { return log_sum_squares_; }