Commit ccaa7407 authored by zhangjinpeng1987's avatar zhangjinpeng1987 Committed by GitHub

get histogram detail (#9)

parent e8b5a0ce
...@@ -79,6 +79,7 @@ using rocksdb::RestoreOptions; ...@@ -79,6 +79,7 @@ using rocksdb::RestoreOptions;
using rocksdb::CompactRangeOptions; using rocksdb::CompactRangeOptions;
using rocksdb::RateLimiter; using rocksdb::RateLimiter;
using rocksdb::NewGenericRateLimiter; using rocksdb::NewGenericRateLimiter;
using rocksdb::HistogramData;
using std::shared_ptr; using std::shared_ptr;
...@@ -116,6 +117,7 @@ struct crocksdb_envoptions_t { EnvOptions rep; }; ...@@ -116,6 +117,7 @@ struct crocksdb_envoptions_t { EnvOptions rep; };
struct crocksdb_ingestexternalfileoptions_t { IngestExternalFileOptions rep; }; struct crocksdb_ingestexternalfileoptions_t { IngestExternalFileOptions rep; };
struct crocksdb_sstfilewriter_t { SstFileWriter* rep; }; struct crocksdb_sstfilewriter_t { SstFileWriter* rep; };
struct crocksdb_ratelimiter_t { RateLimiter* rep; }; struct crocksdb_ratelimiter_t { RateLimiter* rep; };
struct crocksdb_histogramdata_t { HistogramData rep; };
struct crocksdb_compactionfiltercontext_t { struct crocksdb_compactionfiltercontext_t {
CompactionFilter::Context rep; CompactionFilter::Context rep;
...@@ -2032,6 +2034,28 @@ char* crocksdb_options_statistics_get_histogram_string(crocksdb_options_t* opt, ...@@ -2032,6 +2034,28 @@ char* crocksdb_options_statistics_get_histogram_string(crocksdb_options_t* opt,
return nullptr; return nullptr;
} }
unsigned char crocksdb_options_statistics_get_histogram(
crocksdb_options_t* opt,
uint32_t type,
double* median,
double* percentile95,
double* percentile99,
double* average,
double* standard_deviation) {
rocksdb::Statistics* statistics = opt->rep.statistics.get();
if (statistics) {
crocksdb_histogramdata_t data;
statistics->histogramData(type, &data.rep);
*median = data.rep.median;
*percentile95 = data.rep.percentile95;
*percentile99 = data.rep.percentile99;
*average = data.rep.average;
*standard_deviation = data.rep.standard_deviation;
return 1;
}
return 0;
}
void crocksdb_options_set_ratelimiter(crocksdb_options_t *opt, crocksdb_ratelimiter_t *limiter) { void crocksdb_options_set_ratelimiter(crocksdb_options_t *opt, crocksdb_ratelimiter_t *limiter) {
opt->rep.rate_limiter.reset(limiter->rep); opt->rep.rate_limiter.reset(limiter->rep);
limiter->rep = nullptr; limiter->rep = nullptr;
......
...@@ -624,6 +624,14 @@ extern C_ROCKSDB_LIBRARY_API uint64_t crocksdb_options_statistics_get_and_reset_ ...@@ -624,6 +624,14 @@ extern C_ROCKSDB_LIBRARY_API uint64_t crocksdb_options_statistics_get_and_reset_
extern C_ROCKSDB_LIBRARY_API char* extern C_ROCKSDB_LIBRARY_API char*
crocksdb_options_statistics_get_histogram_string(crocksdb_options_t* opt, crocksdb_options_statistics_get_histogram_string(crocksdb_options_t* opt,
uint32_t type); uint32_t type);
extern C_ROCKSDB_LIBRARY_API unsigned char crocksdb_options_statistics_get_histogram(
crocksdb_options_t* opt,
uint32_t type,
double* median,
double* percentile95,
double* percentile99,
double* average,
double* standard_deviation);
extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_max_write_buffer_number( extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_max_write_buffer_number(
crocksdb_options_t*, int); crocksdb_options_t*, int);
......
...@@ -249,6 +249,13 @@ extern "C" { ...@@ -249,6 +249,13 @@ extern "C" {
pub fn crocksdb_options_statistics_get_histogram_string(options: *mut DBOptions, pub fn crocksdb_options_statistics_get_histogram_string(options: *mut DBOptions,
hist_type: DBStatisticsHistogramType) hist_type: DBStatisticsHistogramType)
-> *const c_char; -> *const c_char;
pub fn crocksdb_options_statistics_get_histogram(options: *mut DBOptions,
hist_type: DBStatisticsHistogramType,
median: *mut c_double,
percentile95: *mut c_double,
percentile99: *mut c_double,
average: *mut c_double,
standard_deviation: *mut c_double) -> bool;
pub fn crocksdb_options_set_stats_dump_period_sec(options: *mut DBOptions, v: usize); pub fn crocksdb_options_set_stats_dump_period_sec(options: *mut DBOptions, v: usize);
pub fn crocksdb_options_set_num_levels(options: *mut DBOptions, v: c_int); pub fn crocksdb_options_set_num_levels(options: *mut DBOptions, v: c_int);
pub fn crocksdb_options_set_db_log_dir(options: *mut DBOptions, path: *const c_char); pub fn crocksdb_options_set_db_log_dir(options: *mut DBOptions, path: *const c_char);
......
...@@ -37,5 +37,5 @@ pub use merge_operator::MergeOperands; ...@@ -37,5 +37,5 @@ pub use merge_operator::MergeOperands;
pub use rocksdb::{DB, DBIterator, DBVector, Kv, SeekKey, Writable, WriteBatch, CFHandle, Range, pub use rocksdb::{DB, DBIterator, DBVector, Kv, SeekKey, Writable, WriteBatch, CFHandle, Range,
BackupEngine}; BackupEngine};
pub use rocksdb_options::{BlockBasedOptions, Options, ReadOptions, WriteOptions, RestoreOptions, pub use rocksdb_options::{BlockBasedOptions, Options, ReadOptions, WriteOptions, RestoreOptions,
IngestExternalFileOptions, EnvOptions}; IngestExternalFileOptions, EnvOptions, HistogramData};
pub use slice_transform::SliceTransform; pub use slice_transform::SliceTransform;
...@@ -17,7 +17,7 @@ use crocksdb_ffi::{self, DBWriteBatch, DBCFHandle, DBInstance, DBBackupEngine, ...@@ -17,7 +17,7 @@ use crocksdb_ffi::{self, DBWriteBatch, DBCFHandle, DBInstance, DBBackupEngine,
DBStatisticsTickerType, DBStatisticsHistogramType}; DBStatisticsTickerType, DBStatisticsHistogramType};
use libc::{self, c_int, c_void, size_t}; use libc::{self, c_int, c_void, size_t};
use rocksdb_options::{Options, ReadOptions, UnsafeSnap, WriteOptions, FlushOptions, use rocksdb_options::{Options, ReadOptions, UnsafeSnap, WriteOptions, FlushOptions,
RestoreOptions, IngestExternalFileOptions}; RestoreOptions, IngestExternalFileOptions, HistogramData};
use std::{fs, ptr, slice}; use std::{fs, ptr, slice};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::collections::btree_map::Entry; use std::collections::btree_map::Entry;
...@@ -874,6 +874,12 @@ impl DB { ...@@ -874,6 +874,12 @@ impl DB {
self.opts.get_statistics_histogram_string(hist_type) self.opts.get_statistics_histogram_string(hist_type)
} }
pub fn get_statistics_histogram(&self,
hist_type: DBStatisticsHistogramType)
-> Option<HistogramData> {
self.opts.get_statistics_histogram(hist_type)
}
pub fn get_options(&self) -> &Options { pub fn get_options(&self) -> &Options {
&self.opts &self.opts
} }
......
...@@ -26,6 +26,15 @@ use slice_transform::{SliceTransform, new_slice_transform}; ...@@ -26,6 +26,15 @@ use slice_transform::{SliceTransform, new_slice_transform};
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::mem; use std::mem;
#[derive(Default, Debug)]
pub struct HistogramData {
pub median: f64,
pub percentile95: f64,
pub percentile99: f64,
pub average: f64,
pub standard_deviation: f64,
}
pub struct BlockBasedOptions { pub struct BlockBasedOptions {
inner: *mut DBBlockBasedTableOptions, inner: *mut DBBlockBasedTableOptions,
} }
...@@ -540,6 +549,25 @@ impl Options { ...@@ -540,6 +549,25 @@ impl Options {
} }
} }
pub fn get_statistics_histogram(&self,
hist_type: DBStatisticsHistogramType)
-> Option<HistogramData> {
unsafe {
let mut data = HistogramData::default();
let ret = crocksdb_ffi::crocksdb_options_statistics_get_histogram(self.inner,
hist_type,
&mut data.median,
&mut data.percentile95,
&mut data.percentile99,
&mut data.average,
&mut data.standard_deviation);
if !ret {
return None;
}
Some(data)
}
}
pub fn get_statistics_histogram_string(&self, pub fn get_statistics_histogram_string(&self,
hist_type: DBStatisticsHistogramType) hist_type: DBStatisticsHistogramType)
-> Option<String> { -> Option<String> {
......
...@@ -37,4 +37,5 @@ fn test_db_statistics() { ...@@ -37,4 +37,5 @@ fn test_db_statistics() {
assert!(db.get_and_reset_statistics_ticker_count(TickerType::BlockCacheHit) > 0); assert!(db.get_and_reset_statistics_ticker_count(TickerType::BlockCacheHit) > 0);
assert_eq!(db.get_statistics_ticker_count(TickerType::BlockCacheHit), 0); assert_eq!(db.get_statistics_ticker_count(TickerType::BlockCacheHit), 0);
assert!(db.get_statistics_histogram_string(HistogramType::DbGetMicros).is_some()); assert!(db.get_statistics_histogram_string(HistogramType::DbGetMicros).is_some());
assert!(db.get_statistics_histogram(HistogramType::DbGetMicros).is_some());
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment