namespace folly {
template <typename VT, typename TT>
-BucketedTimeSeries<VT, TT>::BucketedTimeSeries(size_t numBuckets,
- TimeType duration)
+BucketedTimeSeries<VT, TT>::BucketedTimeSeries(size_t nBuckets,
+ TimeType maxDuration)
: firstTime_(1),
latestTime_(0),
- duration_(duration) {
+ duration_(maxDuration) {
// For tracking all-time data we only use total_, and don't need to bother
// with buckets_
if (!isAllTime()) {
- // Round numBuckets down to duration_.count().
+ // Round nBuckets down to duration_.count().
//
// There is no point in having more buckets than our timestamp
// granularity: otherwise we would have buckets that could never be used.
- if (numBuckets > duration_.count()) {
- numBuckets = duration_.count();
+ if (nBuckets > duration_.count()) {
+ nBuckets = duration_.count();
}
- buckets_.resize(numBuckets, Bucket());
+ buckets_.resize(nBuckets, Bucket());
}
}
template <typename VT, typename TT>
bool BucketedTimeSeries<VT, TT>::addValueAggregated(TimeType now,
- const ValueType& sum,
+ const ValueType& total,
int64_t nsamples) {
if (isAllTime()) {
if (UNLIKELY(empty())) {
} else if (now < firstTime_) {
firstTime_ = now;
}
- total_.add(sum, nsamples);
+ total_.add(total, nsamples);
return true;
}
bucketIdx = getBucketIdx(now);
}
- total_.add(sum, nsamples);
- buckets_[bucketIdx].add(sum, nsamples);
+ total_.add(total, nsamples);
+ buckets_[bucketIdx].add(total, nsamples);
return true;
}
template <typename VT, typename TT>
VT BucketedTimeSeries<VT, TT>::sum(TimeType start, TimeType end) const {
- ValueType sum = ValueType();
+ ValueType total = ValueType();
forEachBucket(start, end, [&](const Bucket& bucket,
TimeType bucketStart,
TimeType nextBucketStart) -> bool {
- sum += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
+ total += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
bucket.sum);
return true;
});
- return sum;
+ return total;
}
template <typename VT, typename TT>
uint64_t BucketedTimeSeries<VT, TT>::count(TimeType start, TimeType end) const {
- uint64_t count = 0;
+ uint64_t sample_count = 0;
forEachBucket(start, end, [&](const Bucket& bucket,
TimeType bucketStart,
TimeType nextBucketStart) -> bool {
- count += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
+ sample_count += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
bucket.count);
return true;
});
- return count;
+ return sample_count;
}
template <typename VT, typename TT>
template <typename ReturnType>
ReturnType BucketedTimeSeries<VT, TT>::avg(TimeType start, TimeType end) const {
- ValueType sum = ValueType();
- uint64_t count = 0;
+ ValueType total = ValueType();
+ uint64_t sample_count = 0;
forEachBucket(start, end, [&](const Bucket& bucket,
TimeType bucketStart,
TimeType nextBucketStart) -> bool {
- sum += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
+ total += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
bucket.sum);
- count += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
+ sample_count += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
bucket.count);
return true;
});
- if (count == 0) {
+ if (sample_count == 0) {
return ReturnType(0);
}
- return detail::avgHelper<ReturnType>(sum, count);
+ return detail::avgHelper<ReturnType>(total, sample_count);
}
/*
template <typename VT, typename TT>
MultiLevelTimeSeries<VT, TT>::MultiLevelTimeSeries(
- size_t numBuckets,
- size_t numLevels,
+ size_t nBuckets,
+ size_t nLevels,
const TimeType levelDurations[])
: cachedTime_(0),
cachedSum_(0),
cachedCount_(0) {
- CHECK_GT(numLevels, 0);
+ CHECK_GT(nLevels, 0);
CHECK(levelDurations);
- levels_.reserve(numLevels);
- for (int i = 0; i < numLevels; ++i) {
+ levels_.reserve(nLevels);
+ for (int i = 0; i < nLevels; ++i) {
if (levelDurations[i] == TT(0)) {
- CHECK_EQ(i, numLevels - 1);
+ CHECK_EQ(i, nLevels - 1);
} else if (i > 0) {
CHECK(levelDurations[i-1] < levelDurations[i]);
}
- levels_.emplace_back(numBuckets, levelDurations[i]);
+ levels_.emplace_back(nBuckets, levelDurations[i]);
}
}
template <typename VT, typename TT>
void MultiLevelTimeSeries<VT, TT>::addValueAggregated(TimeType now,
- const ValueType& sum,
+ const ValueType& total,
int64_t nsamples) {
if (cachedTime_ != now) {
flush();
cachedTime_ = now;
}
- cachedSum_ += sum;
+ cachedSum_ += total;
cachedCount_ += nsamples;
}
template <typename ReturnType>
ReturnType TimeseriesHistogram<T, TT, C>::avg(int level) const {
ValueType total = ValueType();
- int64_t count = 0;
+ int64_t nsamples = 0;
for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
const auto& levelObj = buckets_.getByIndex(b).getLevel(level);
total += levelObj.sum();
- count += levelObj.count();
+ nsamples += levelObj.count();
}
- return folly::detail::avgHelper<ReturnType>(total, count);
+ return folly::detail::avgHelper<ReturnType>(total, nsamples);
}
template <class T, class TT, class C>
ReturnType TimeseriesHistogram<T, TT, C>::avg(TimeType start,
TimeType end) const {
ValueType total = ValueType();
- int64_t count = 0;
+ int64_t nsamples = 0;
for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
const auto& levelObj = buckets_.getByIndex(b).getLevel(start, end);
total += levelObj.sum(start, end);
- count += levelObj.count(start, end);
+ nsamples += levelObj.count(start, end);
}
- return folly::detail::avgHelper<ReturnType>(total, count);
+ return folly::detail::avgHelper<ReturnType>(total, nsamples);
}
template <class T, class TT, class C>