diff --git a/HISTORY.md b/HISTORY.md index e9698ab3b..c299a0505 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,7 @@ # Rocksdb Change Log ## Unreleased +### Public API Change +* For users of `Statistics` objects created via `CreateDBStatistics()`, the format of the string returned by its `ToString()` method has changed. ## 5.14.0 (5/16/2018) ### Public API Change diff --git a/include/rocksdb/statistics.h b/include/rocksdb/statistics.h index 1a4f699db..30e79b099 100644 --- a/include/rocksdb/statistics.h +++ b/include/rocksdb/statistics.h @@ -619,6 +619,8 @@ struct HistogramData { // zero-initialize new members since old Statistics::histogramData() // implementations won't write them. double max = 0.0; + uint64_t count = 0; + uint64_t sum = 0; }; enum StatsLevel { diff --git a/monitoring/histogram.cc b/monitoring/histogram.cc index 4970df7bd..d5ac07c90 100644 --- a/monitoring/histogram.cc +++ b/monitoring/histogram.cc @@ -235,6 +235,8 @@ void HistogramStat::Data(HistogramData * const data) const { data->max = static_cast(max()); data->average = Average(); data->standard_deviation = StandardDeviation(); + data->count = num(); + data->sum = sum(); } void HistogramImpl::Clear() { diff --git a/monitoring/statistics.cc b/monitoring/statistics.cc index 938704312..59ce3d9e0 100644 --- a/monitoring/statistics.cc +++ b/monitoring/statistics.cc @@ -169,11 +169,17 @@ std::string StatisticsImpl::ToString() const { char buffer[kTmpStrBufferSize]; HistogramData hData; getHistogramImplLocked(h.first)->Data(&hData); - snprintf( + // don't handle failures - buffer should always be big enough and arguments + // should be provided correctly + int ret = snprintf( buffer, kTmpStrBufferSize, - "%s statistics Percentiles :=> 50 : %f 95 : %f 99 : %f 100 : %f\n", - h.second.c_str(), hData.median, hData.percentile95, - hData.percentile99, hData.max); + "%s P50 : %f P95 : %f P99 : %f P100 : %f COUNT : %" PRIu64 " SUM : %" + PRIu64 "\n", h.second.c_str(), hData.median, hData.percentile95, + hData.percentile99, hData.max, hData.count, hData.sum); + if (ret < 0 || ret >= kTmpStrBufferSize) { + assert(false); + continue; + } res.append(buffer); } }