support get statistics

master
siddontang 8 years ago committed by Karl Hobley
parent 42c5bb92dc
commit edb0859029
  1. 1
      src/ffi.rs
  2. 24
      src/rocksdb_options.rs

@ -207,6 +207,7 @@ extern "C" {
pub fn rocksdb_options_set_report_bg_io_stats(options: DBOptions, v: c_int);
pub fn rocksdb_options_set_wal_recovery_mode(options: DBOptions, mode: DBRecoveryMode);
pub fn rocksdb_options_enable_statistics(options: DBOptions);
pub fn rocksdb_options_statistics_get_string(options: DBOptions) -> *const c_char;
pub fn rocksdb_options_set_stats_dump_period_sec(options: DBOptions, v: usize);
pub fn rocksdb_options_set_num_levels(options: DBOptions, v: c_int);
pub fn rocksdb_filterpolicy_create_bloom_full(bits_per_key: c_int)

@ -13,8 +13,8 @@
// limitations under the License.
//
extern crate libc;
use self::libc::{c_int,size_t};
use std::ffi::CString;
use self::libc::{c_int, size_t, c_void};
use std::ffi::{CStr, CString};
use std::mem;
use rocksdb_ffi::{self, DBCompressionType, DBRecoveryMode};
@ -379,6 +379,22 @@ impl Options {
}
}
pub fn get_statistics(&self) -> Option<String> {
unsafe {
let value = rocksdb_ffi::rocksdb_options_statistics_get_string(self.inner);
if value.is_null() {
return None;
}
// Must valid UTF-8 format.
let s = CStr::from_ptr(value).to_str().unwrap().to_owned();
libc::free(value as *mut c_void);
Some(s)
}
}
pub fn set_stats_dump_period_sec(&mut self, period: usize) {
unsafe {
rocksdb_ffi::rocksdb_options_set_stats_dump_period_sec(self.inner,
@ -454,5 +470,9 @@ mod tests {
let mut opts = Options::default();
opts.enable_statistics();
opts.set_stats_dump_period_sec(60);
assert!(opts.get_statistics().is_some());
let opts = Options::default();
assert!(opts.get_statistics().is_none());
}
}

Loading…
Cancel
Save