X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fstats%2FTimeseriesHistogram.h;h=d5ce089d75b1191e3f38b2fb339da6b55f5ef158;hp=9aead54ea07dc55da0bffa317bd1c44e1407925f;hb=bd8228d9514fb717cb495b28de9974b447f08a45;hpb=dfea2768fbbea2adfaf66b7e0fc85eca2049b889 diff --git a/folly/stats/TimeseriesHistogram.h b/folly/stats/TimeseriesHistogram.h index 9aead54e..d5ce089d 100644 --- a/folly/stats/TimeseriesHistogram.h +++ b/folly/stats/TimeseriesHistogram.h @@ -147,25 +147,48 @@ class TimeseriesHistogram { } /* Average of values at the given timeseries level (all buckets). */ - template - ReturnType avg(int level) const; + template + ReturnType avg(int level) const { + auto total = ValueType(); + int64_t nsamples = 0; + computeAvgData(&total, &nsamples, level); + return folly::detail::avgHelper(total, nsamples); + } /* Average of values added during the given interval (all buckets). */ - template - ReturnType avg(TimeType start, TimeType end) const; + template + ReturnType avg(TimeType start, TimeType end) const { + auto total = ValueType(); + int64_t nsamples = 0; + computeAvgData(&total, &nsamples, start, end); + return folly::detail::avgHelper(total, nsamples); + } /* * Rate at the given timeseries level (all buckets). * This is the sum of all values divided by the time interval (in seconds). */ - ValueType rate(int level) const; + template + ReturnType rate(int level) const { + auto total = ValueType(); + TimeType elapsed(0); + computeRateData(&total, &elapsed, level); + return folly::detail::rateHelper( + total, elapsed); + } /* * Rate for the given interval (all buckets). * This is the sum of all values divided by the time interval (in seconds). */ - template - ReturnType rate(TimeType start, TimeType end) const; + template + ReturnType rate(TimeType start, TimeType end) const { + auto total = ValueType(); + TimeType elapsed(0); + computeRateData(&total, &elapsed, start, end); + return folly::detail::rateHelper( + total, elapsed); + } /* * Update every underlying timeseries object with the given timestamp. You @@ -319,10 +342,22 @@ class TimeseriesHistogram { */ void maybeHandleSingleUniqueValue(const ValueType& value); + void computeAvgData(ValueType* total, int64_t* nsamples, int level) const; + void computeAvgData( + ValueType* total, + int64_t* nsamples, + TimeType start, + TimeType end) const; + void computeRateData(ValueType* total, TimeType* elapsed, int level) const; + void computeRateData( + ValueType* total, + TimeType* elapsed, + TimeType start, + TimeType end) const; + folly::detail::HistogramBuckets buckets_; bool haveNotSeenValue_; bool singleUniqueValue_; ValueType firstValue_; }; - } // folly