Commit 98dcfd35 authored by Qingyuan Deng's avatar Qingyuan Deng Committed by Dave Watson

<Thrift perftest> 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
parent 5e8ce83b
......@@ -202,9 +202,9 @@ class HistogramBuckets {
}
private:
const ValueType bucketSize_;
const ValueType min_;
const ValueType max_;
ValueType bucketSize_;
ValueType min_;
ValueType max_;
std::vector<BucketType> 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() ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment