Add histogramType for statistics
This commit is contained in:
parent
144066a8ff
commit
320ae72e17
2
Makefile
2
Makefile
@ -420,7 +420,7 @@ ldb: tools/ldb.o $(LIBOBJECTS)
|
||||
# ---------------------------------------------------------------------------
|
||||
# Jni stuff
|
||||
# ---------------------------------------------------------------------------
|
||||
JNI_NATIVE_SOURCES = ./java/rocksjni/rocksjni.cc ./java/rocksjni/options.cc ./java/rocksjni/write_batch.cc
|
||||
JNI_NATIVE_SOURCES = ./java/rocksjni/rocksjni.cc ./java/rocksjni/options.cc ./java/rocksjni/write_batch.cc ./java/rocksjni/statistics.cc
|
||||
|
||||
JAVA_INCLUDE = -I/usr/lib/jvm/java-openjdk/include/ -I/usr/lib/jvm/java-openjdk/include/linux
|
||||
ROCKSDBJNILIB = ./java/librocksdbjni.so
|
||||
|
@ -16,7 +16,7 @@ sample: java
|
||||
javac -cp $(ROCKSDB_JAR) RocksDBSample.java
|
||||
@rm -rf /tmp/rocksdbjni
|
||||
@rm -rf /tmp/rocksdbjni_not_found
|
||||
java -ea -Djava.library.path=.:../ -cp ".:./*" RocksDBSample /tmp/rocksdbjni
|
||||
java -ea -Djava.library.path=.:../ -cp ".:./*" -Xcheck:jni RocksDBSample /tmp/rocksdbjni
|
||||
@rm -rf /tmp/rocksdbjni
|
||||
@rm -rf /tmp/rocksdbjni_not_found
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class RocksDBSample {
|
||||
.setDisableSeekCompaction(true)
|
||||
.setBlockSize(64 * SizeUnit.KB)
|
||||
.setMaxBackgroundCompactions(10);
|
||||
Statistics stats = new Statistics(options.statisticsPtr());
|
||||
Statistics stats = options.statisticsPtr();
|
||||
|
||||
assert(options.createIfMissing() == true);
|
||||
assert(options.writeBufferSize() == 8 * SizeUnit.KB);
|
||||
@ -124,16 +124,24 @@ public class RocksDBSample {
|
||||
writeOpts.dispose();
|
||||
|
||||
try {
|
||||
for(TickerType statsType : TickerType.values()) {
|
||||
for (TickerType statsType : TickerType.values()) {
|
||||
stats.getTickerCount(statsType);
|
||||
}
|
||||
System.out.println("getTickerCount() passed.");
|
||||
}
|
||||
catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed in call to getTickerCount()");
|
||||
assert(false); //Should never reach here.
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
for (HistogramType histogramType : HistogramType.values()) {
|
||||
HistogramData data = stats.geHistogramData(histogramType);
|
||||
}
|
||||
System.out.println("geHistogramData() passed.");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed in call to geHistogramData()");
|
||||
assert(false); //Should never reach here.
|
||||
}
|
||||
} catch (RocksDBException e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
|
@ -220,13 +220,16 @@ public class Options {
|
||||
*
|
||||
* @see createStatistics()
|
||||
*/
|
||||
public long statisticsPtr() {
|
||||
public Statistics statisticsPtr() {
|
||||
assert(isInitialized());
|
||||
|
||||
long statsPtr = statisticsPtr(nativeHandle_);
|
||||
assert(statsPtr != 0);
|
||||
if(statsPtr == 0) {
|
||||
createStatistics();
|
||||
statsPtr = statisticsPtr(nativeHandle_);
|
||||
}
|
||||
|
||||
return statsPtr;
|
||||
return new Statistics(statsPtr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ package org.rocksdb;
|
||||
*/
|
||||
public class Statistics {
|
||||
|
||||
private long statsHandle_;
|
||||
private final long statsHandle_;
|
||||
|
||||
public Statistics(long statsHandle) {
|
||||
statsHandle_ = statsHandle;
|
||||
@ -22,9 +22,16 @@ public class Statistics {
|
||||
return getTickerCount0(tickerType.getValue(), statsHandle_);
|
||||
}
|
||||
|
||||
public HistogramData geHistogramData(HistogramType histogramType) {
|
||||
assert(isInitialized());
|
||||
HistogramData hist = geHistogramData0(histogramType.getValue(), statsHandle_);
|
||||
return hist;
|
||||
}
|
||||
|
||||
private boolean isInitialized() {
|
||||
return (statsHandle_ != 0);
|
||||
}
|
||||
|
||||
private native long getTickerCount0(int ticker, long handle);
|
||||
private native long getTickerCount0(int tickerType, long handle);
|
||||
private native HistogramData geHistogramData0(int histogramType, long handle);
|
||||
}
|
||||
|
@ -170,5 +170,15 @@ class WriteBatchJni {
|
||||
reinterpret_cast<jlong>(wb));
|
||||
}
|
||||
};
|
||||
|
||||
class HistogramDataJni {
|
||||
public:
|
||||
static jmethodID getConstructorMethodId(JNIEnv* env, jclass jclazz) {
|
||||
static jmethodID mid = env->GetMethodID(
|
||||
jclazz, "<init>", "(DDDDD)V");
|
||||
assert(mid != nullptr);
|
||||
return mid;
|
||||
}
|
||||
};
|
||||
} // namespace rocksdb
|
||||
#endif // JAVA_ROCKSJNI_PORTAL_H_
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "include/org_rocksdb_Statistics.h"
|
||||
#include "rocksjni/portal.h"
|
||||
#include "rocksdb/statistics.h"
|
||||
#include <iostream>
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_Statistics
|
||||
@ -20,9 +21,26 @@
|
||||
* Signature: (IJ)J
|
||||
*/
|
||||
jlong Java_org_rocksdb_Statistics_getTickerCount0(
|
||||
JNIEnv* env, jobject jobj, int ticker, jlong handle) {
|
||||
JNIEnv* env, jobject jobj, int tickerType, jlong handle) {
|
||||
auto st = reinterpret_cast<rocksdb::Statistics*>(handle);
|
||||
assert(st != nullptr);
|
||||
|
||||
return st->getTickerCount(static_cast<rocksdb::Tickers>(ticker));
|
||||
return st->getTickerCount(static_cast<rocksdb::Tickers>(tickerType));
|
||||
}
|
||||
|
||||
jobject Java_org_rocksdb_Statistics_geHistogramData0(
|
||||
JNIEnv* env, jobject jobj, int histogramType, jlong handle) {
|
||||
auto st = reinterpret_cast<rocksdb::Statistics*>(handle);
|
||||
assert(st != nullptr);
|
||||
|
||||
rocksdb::HistogramData data;
|
||||
st->histogramData(static_cast<rocksdb::Histograms>(histogramType),
|
||||
&data);
|
||||
|
||||
// Don't reuse class pointer
|
||||
jclass jclazz = env->FindClass("org/rocksdb/HistogramData");
|
||||
jmethodID mid = rocksdb::HistogramDataJni::getConstructorMethodId(
|
||||
env, jclazz);
|
||||
return env->NewObject(jclazz, mid, data.median, data.percentile95,
|
||||
data.percentile99, data.average, data.standard_deviation);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user