From a914a1c6dc37c63ac06186767235aa9d8f17469c Mon Sep 17 00:00:00 2001 From: Adam Singer Date: Fri, 14 Dec 2018 14:18:17 -0800 Subject: [PATCH] Add `getMin`, `getMax`, `getCount`, `getSum` to `HistogramData` class object. (#4742) Summary: Expose common stats min,max,count,sum via statistics JNI. These stats are not fully exposed on the Java side as is, but are available on the native side. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4742 Differential Revision: D13403766 Pulled By: ajkr fbshipit-source-id: 5b70f7bd3fb7490aab73dcbd09f13490fce5c773 --- include/rocksdb/statistics.h | 1 + java/rocksjni/portal.h | 2 +- java/rocksjni/statistics.cc | 3 +- .../main/java/org/rocksdb/HistogramData.java | 33 ++++++++++++++++++- .../test/java/org/rocksdb/StatisticsTest.java | 8 +++++ monitoring/histogram.cc | 1 + 6 files changed, 45 insertions(+), 3 deletions(-) diff --git a/include/rocksdb/statistics.h b/include/rocksdb/statistics.h index 6d5118985..d2d0a8d27 100644 --- a/include/rocksdb/statistics.h +++ b/include/rocksdb/statistics.h @@ -430,6 +430,7 @@ struct HistogramData { double max = 0.0; uint64_t count = 0; uint64_t sum = 0; + double min = 0.0; }; enum StatsLevel { diff --git a/java/rocksjni/portal.h b/java/rocksjni/portal.h index 5c5829c4b..f739886d2 100644 --- a/java/rocksjni/portal.h +++ b/java/rocksjni/portal.h @@ -1612,7 +1612,7 @@ class HistogramDataJni : public JavaClass { return nullptr; } - static jmethodID mid = env->GetMethodID(jclazz, "", "(DDDDD)V"); + static jmethodID mid = env->GetMethodID(jclazz, "", "(DDDDDDJJD)V"); assert(mid != nullptr); return mid; } diff --git a/java/rocksjni/statistics.cc b/java/rocksjni/statistics.cc index dd58cf60c..df137dc76 100644 --- a/java/rocksjni/statistics.cc +++ b/java/rocksjni/statistics.cc @@ -202,7 +202,8 @@ jobject Java_org_rocksdb_Statistics_getHistogramData(JNIEnv* env, return env->NewObject(jclazz, mid, data.median, data.percentile95, data.percentile99, data.average, - data.standard_deviation); + data.standard_deviation, data.max, data.count, + data.sum, data.min); } /* diff --git a/java/src/main/java/org/rocksdb/HistogramData.java b/java/src/main/java/org/rocksdb/HistogramData.java index 11798eb59..81d890883 100644 --- a/java/src/main/java/org/rocksdb/HistogramData.java +++ b/java/src/main/java/org/rocksdb/HistogramData.java @@ -11,15 +11,30 @@ public class HistogramData { private final double percentile99_; private final double average_; private final double standardDeviation_; + private final double max_; + private final long count_; + private final long sum_; + private final double min_; + + public HistogramData(final double median, final double percentile95, + final double percentile99, final double average, + final double standardDeviation) { + this(median, percentile95, percentile99, average, standardDeviation, 0.0, 0, 0, 0.0); + } public HistogramData(final double median, final double percentile95, final double percentile99, final double average, - final double standardDeviation) { + final double standardDeviation, final double max, final long count, + final long sum, final double min) { median_ = median; percentile95_ = percentile95; percentile99_ = percentile99; average_ = average; standardDeviation_ = standardDeviation; + min_ = min; + max_ = max; + count_ = count; + sum_ = sum; } public double getMedian() { @@ -41,4 +56,20 @@ public class HistogramData { public double getStandardDeviation() { return standardDeviation_; } + + public double getMax() { + return max_; + } + + public long getCount() { + return count_; + } + + public long getSum() { + return sum_; + } + + public double getMin() { + return min_; + } } diff --git a/java/src/test/java/org/rocksdb/StatisticsTest.java b/java/src/test/java/org/rocksdb/StatisticsTest.java index 2103c2fc7..fbd255bdb 100644 --- a/java/src/test/java/org/rocksdb/StatisticsTest.java +++ b/java/src/test/java/org/rocksdb/StatisticsTest.java @@ -96,6 +96,14 @@ public class StatisticsTest { final HistogramData histogramData = statistics.getHistogramData(HistogramType.BYTES_PER_READ); assertThat(histogramData).isNotNull(); assertThat(histogramData.getAverage()).isGreaterThan(0); + assertThat(histogramData.getMedian()).isGreaterThan(0); + assertThat(histogramData.getPercentile95()).isGreaterThan(0); + assertThat(histogramData.getPercentile99()).isGreaterThan(0); + assertThat(histogramData.getStandardDeviation()).isEqualTo(0.00); + assertThat(histogramData.getMax()).isGreaterThan(0); + assertThat(histogramData.getCount()).isGreaterThan(0); + assertThat(histogramData.getSum()).isGreaterThan(0); + assertThat(histogramData.getMin()).isGreaterThan(0); } } diff --git a/monitoring/histogram.cc b/monitoring/histogram.cc index d5ac07c90..4bc7139d3 100644 --- a/monitoring/histogram.cc +++ b/monitoring/histogram.cc @@ -237,6 +237,7 @@ void HistogramStat::Data(HistogramData * const data) const { data->standard_deviation = StandardDeviation(); data->count = num(); data->sum = sum(); + data->min = static_cast(min()); } void HistogramImpl::Clear() {