From: Qingyuan Deng Date: Fri, 7 Feb 2014 22:03:19 +0000 (-0800) Subject: folly: modify Histogram const, add substract X-Git-Tag: v0.22.0~698 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=98dcfd35f87d4498558cb0509f59dbbd2270b917;ds=sidebyside folly: modify Histogram const, add substract Summary: This diff is a split from D1157286 for folly part; adds a substract function which substracts a histogram data from another; modifies some of the const specifiers in the Histogram class. Test Plan: tested on the thrift perftest by adding x-th percentile latency stats Reviewed By: andrei.alexandrescu@fb.com FB internal diff: D1158270 --- diff --git a/folly/stats/Histogram.h b/folly/stats/Histogram.h index 7a0c0db9..77573a17 100644 --- a/folly/stats/Histogram.h +++ b/folly/stats/Histogram.h @@ -202,9 +202,9 @@ class HistogramBuckets { } private: - const ValueType bucketSize_; - const ValueType min_; - const ValueType max_; + ValueType bucketSize_; + ValueType min_; + ValueType max_; std::vector buckets_; }; @@ -259,8 +259,24 @@ class Histogram { } } + /* Subtract another histogram data from the histogram */ + void subtract(const Histogram &hist) { + // the two histogram bucket definitions must match to support + // subtract. + if (getBucketSize() != hist.getBucketSize() || + getMin() != hist.getMin() || + getMax() != hist.getMax() || + getNumBuckets() != hist.getNumBuckets() ) { + throw std::invalid_argument("Cannot subtract input histogram."); + } + + for (int i = 0; i < buckets_.getNumBuckets(); i++) { + buckets_.getByIndex(i) -= hist.buckets_.getByIndex(i); + } + } + /* Merge two histogram data together */ - void merge(Histogram &hist) { + void merge(const Histogram &hist) { // the two histogram bucket definitions must match to support // a merge. if (getBucketSize() != hist.getBucketSize() || @@ -276,7 +292,7 @@ class Histogram { } /* Copy bucket values from another histogram */ - void copy(Histogram &hist) { + void copy(const Histogram &hist) { // the two histogram bucket definition must match if (getBucketSize() != hist.getBucketSize() || getMin() != hist.getMin() ||