2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2014-04-15 06:08:04 +02:00
|
|
|
//
|
|
|
|
// This file implements the "bridge" between Java and C++ and enables
|
|
|
|
// calling c++ rocksdb::Statistics methods from Java side.
|
|
|
|
|
|
|
|
#include <jni.h>
|
2017-07-12 08:19:53 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <set>
|
2014-04-15 06:08:04 +02:00
|
|
|
|
|
|
|
#include "include/org_rocksdb_Statistics.h"
|
2018-04-13 02:55:14 +02:00
|
|
|
#include "rocksdb/statistics.h"
|
2014-04-15 06:08:04 +02:00
|
|
|
#include "rocksjni/portal.h"
|
2017-07-12 08:19:53 +02:00
|
|
|
#include "rocksjni/statisticsjni.h"
|
2014-04-15 06:08:04 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
2017-07-12 08:19:53 +02:00
|
|
|
* Method: newStatistics
|
|
|
|
* Signature: ()J
|
2014-04-15 06:08:04 +02:00
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jlong Java_org_rocksdb_Statistics_newStatistics__(
|
|
|
|
JNIEnv* env, jclass jcls) {
|
|
|
|
return Java_org_rocksdb_Statistics_newStatistics___3BJ(
|
|
|
|
env, jcls, nullptr, 0);
|
2014-04-17 06:38:33 +02:00
|
|
|
}
|
|
|
|
|
2014-04-17 07:00:44 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
2017-07-12 08:19:53 +02:00
|
|
|
* Method: newStatistics
|
|
|
|
* Signature: (J)J
|
2014-04-17 07:00:44 +02:00
|
|
|
*/
|
2017-07-12 08:19:53 +02:00
|
|
|
jlong Java_org_rocksdb_Statistics_newStatistics__J(
|
|
|
|
JNIEnv* env, jclass jcls, jlong jother_statistics_handle) {
|
|
|
|
return Java_org_rocksdb_Statistics_newStatistics___3BJ(
|
|
|
|
env, jcls, nullptr, jother_statistics_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: newStatistics
|
|
|
|
* Signature: ([B)J
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jlong Java_org_rocksdb_Statistics_newStatistics___3B(
|
|
|
|
JNIEnv* env, jclass jcls, jbyteArray jhistograms) {
|
|
|
|
return Java_org_rocksdb_Statistics_newStatistics___3BJ(
|
|
|
|
env, jcls, jhistograms, 0);
|
2017-07-12 08:19:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: newStatistics
|
|
|
|
* Signature: ([BJ)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_Statistics_newStatistics___3BJ(
|
2019-02-22 23:36:38 +01:00
|
|
|
JNIEnv* env, jclass, jbyteArray jhistograms, jlong jother_statistics_handle) {
|
2017-07-12 08:19:53 +02:00
|
|
|
std::shared_ptr<rocksdb::Statistics>* pSptr_other_statistics = nullptr;
|
|
|
|
if (jother_statistics_handle > 0) {
|
|
|
|
pSptr_other_statistics =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Statistics>*>(
|
|
|
|
jother_statistics_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<uint32_t> histograms;
|
|
|
|
if (jhistograms != nullptr) {
|
|
|
|
const jsize len = env->GetArrayLength(jhistograms);
|
|
|
|
if (len > 0) {
|
|
|
|
jbyte* jhistogram = env->GetByteArrayElements(jhistograms, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jhistogram == nullptr) {
|
2017-07-12 08:19:53 +02:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (jsize i = 0; i < len; i++) {
|
|
|
|
const rocksdb::Histograms histogram =
|
|
|
|
rocksdb::HistogramTypeJni::toCppHistograms(jhistogram[i]);
|
|
|
|
histograms.emplace(histogram);
|
|
|
|
}
|
|
|
|
|
|
|
|
env->ReleaseByteArrayElements(jhistograms, jhistogram, JNI_ABORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<rocksdb::Statistics> sptr_other_statistics = nullptr;
|
|
|
|
if (pSptr_other_statistics != nullptr) {
|
2018-04-13 02:55:14 +02:00
|
|
|
sptr_other_statistics = *pSptr_other_statistics;
|
2017-07-12 08:19:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto* pSptr_statistics = new std::shared_ptr<rocksdb::StatisticsJni>(
|
|
|
|
new rocksdb::StatisticsJni(sptr_other_statistics, histograms));
|
2014-04-17 06:55:15 +02:00
|
|
|
|
2017-07-12 08:19:53 +02:00
|
|
|
return reinterpret_cast<jlong>(pSptr_statistics);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
void Java_org_rocksdb_Statistics_disposeInternal(
|
|
|
|
JNIEnv*, jobject, jlong jhandle) {
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jhandle > 0) {
|
2017-07-12 08:19:53 +02:00
|
|
|
auto* pSptr_statistics =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Statistics>*>(jhandle);
|
|
|
|
delete pSptr_statistics;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: statsLevel
|
|
|
|
* Signature: (J)B
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jbyte Java_org_rocksdb_Statistics_statsLevel(
|
|
|
|
JNIEnv*, jobject, jlong jhandle) {
|
2017-07-12 08:19:53 +02:00
|
|
|
auto* pSptr_statistics =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Statistics>*>(jhandle);
|
|
|
|
assert(pSptr_statistics != nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
return rocksdb::StatsLevelJni::toJavaStatsLevel(
|
2019-03-01 19:39:00 +01:00
|
|
|
pSptr_statistics->get()->get_stats_level());
|
2017-07-12 08:19:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: setStatsLevel
|
|
|
|
* Signature: (JB)V
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
void Java_org_rocksdb_Statistics_setStatsLevel(
|
|
|
|
JNIEnv*, jobject, jlong jhandle, jbyte jstats_level) {
|
2017-07-12 08:19:53 +02:00
|
|
|
auto* pSptr_statistics =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Statistics>*>(jhandle);
|
|
|
|
assert(pSptr_statistics != nullptr);
|
|
|
|
auto stats_level = rocksdb::StatsLevelJni::toCppStatsLevel(jstats_level);
|
2019-03-01 19:39:00 +01:00
|
|
|
pSptr_statistics->get()->set_stats_level(stats_level);
|
2017-07-12 08:19:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: getTickerCount
|
|
|
|
* Signature: (JB)J
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jlong Java_org_rocksdb_Statistics_getTickerCount(
|
|
|
|
JNIEnv*, jobject, jlong jhandle, jbyte jticker_type) {
|
2017-07-12 08:19:53 +02:00
|
|
|
auto* pSptr_statistics =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Statistics>*>(jhandle);
|
|
|
|
assert(pSptr_statistics != nullptr);
|
|
|
|
auto ticker = rocksdb::TickerTypeJni::toCppTickers(jticker_type);
|
2019-02-22 23:36:38 +01:00
|
|
|
uint64_t count = pSptr_statistics->get()->getTickerCount(ticker);
|
|
|
|
return static_cast<jlong>(count);
|
2017-07-12 08:19:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: getAndResetTickerCount
|
|
|
|
* Signature: (JB)J
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jlong Java_org_rocksdb_Statistics_getAndResetTickerCount(
|
|
|
|
JNIEnv*, jobject, jlong jhandle, jbyte jticker_type) {
|
2017-07-12 08:19:53 +02:00
|
|
|
auto* pSptr_statistics =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Statistics>*>(jhandle);
|
|
|
|
assert(pSptr_statistics != nullptr);
|
|
|
|
auto ticker = rocksdb::TickerTypeJni::toCppTickers(jticker_type);
|
|
|
|
return pSptr_statistics->get()->getAndResetTickerCount(ticker);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: getHistogramData
|
|
|
|
* Signature: (JB)Lorg/rocksdb/HistogramData;
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jobject Java_org_rocksdb_Statistics_getHistogramData(
|
|
|
|
JNIEnv* env, jobject, jlong jhandle, jbyte jhistogram_type) {
|
2017-07-12 08:19:53 +02:00
|
|
|
auto* pSptr_statistics =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Statistics>*>(jhandle);
|
|
|
|
assert(pSptr_statistics != nullptr);
|
|
|
|
|
2019-02-22 23:36:38 +01:00
|
|
|
// TODO(AR) perhaps better to construct a Java Object Wrapper that
|
|
|
|
// uses ptr to C++ `new HistogramData`
|
|
|
|
rocksdb::HistogramData data;
|
|
|
|
|
2017-07-12 08:19:53 +02:00
|
|
|
auto histogram = rocksdb::HistogramTypeJni::toCppHistograms(jhistogram_type);
|
|
|
|
pSptr_statistics->get()->histogramData(
|
|
|
|
static_cast<rocksdb::Histograms>(histogram), &data);
|
2014-04-17 06:55:15 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
jclass jclazz = rocksdb::HistogramDataJni::getJClass(env);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jclazz == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
jmethodID mid = rocksdb::HistogramDataJni::getConstructorMethodId(env);
|
|
|
|
if (mid == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception occurred accessing method
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
return env->NewObject(jclazz, mid, data.median, data.percentile95,
|
|
|
|
data.percentile99, data.average,
|
2018-12-14 23:18:17 +01:00
|
|
|
data.standard_deviation, data.max, data.count,
|
|
|
|
data.sum, data.min);
|
2014-04-15 07:16:10 +02:00
|
|
|
}
|
2017-07-12 08:19:53 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: getHistogramString
|
|
|
|
* Signature: (JB)Ljava/lang/String;
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jstring Java_org_rocksdb_Statistics_getHistogramString(
|
|
|
|
JNIEnv* env, jobject, jlong jhandle, jbyte jhistogram_type) {
|
2017-07-12 08:19:53 +02:00
|
|
|
auto* pSptr_statistics =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Statistics>*>(jhandle);
|
|
|
|
assert(pSptr_statistics != nullptr);
|
|
|
|
auto histogram = rocksdb::HistogramTypeJni::toCppHistograms(jhistogram_type);
|
|
|
|
auto str = pSptr_statistics->get()->getHistogramString(histogram);
|
|
|
|
return env->NewStringUTF(str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: reset
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
void Java_org_rocksdb_Statistics_reset(
|
|
|
|
JNIEnv* env, jobject, jlong jhandle) {
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* pSptr_statistics =
|
2017-07-12 08:19:53 +02:00
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Statistics>*>(jhandle);
|
|
|
|
assert(pSptr_statistics != nullptr);
|
|
|
|
rocksdb::Status s = pSptr_statistics->get()->Reset();
|
|
|
|
if (!s.ok()) {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
2017-07-12 08:19:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_Statistics
|
|
|
|
* Method: toString
|
|
|
|
* Signature: (J)Ljava/lang/String;
|
|
|
|
*/
|
2019-02-22 23:36:38 +01:00
|
|
|
jstring Java_org_rocksdb_Statistics_toString(
|
|
|
|
JNIEnv* env, jobject, jlong jhandle) {
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* pSptr_statistics =
|
2017-07-12 08:19:53 +02:00
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::Statistics>*>(jhandle);
|
|
|
|
assert(pSptr_statistics != nullptr);
|
|
|
|
auto str = pSptr_statistics->get()->ToString();
|
|
|
|
return env->NewStringUTF(str.c_str());
|
|
|
|
}
|