Skip to content

Commit

Permalink
Expose rocksdb cumulative statistics and histograms (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedSoliman committed Feb 11, 2024
1 parent 4336985 commit 5fca3d6
Show file tree
Hide file tree
Showing 4 changed files with 864 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/db_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::sync::Arc;

use libc::{self, c_char, c_double, c_int, c_uchar, c_uint, c_void, size_t};

use crate::statistics::{Histogram, HistogramData, StatsLevel};
use crate::{
compaction_filter::{self, CompactionFilterCallback, CompactionFilterFn},
compaction_filter_factory::{self, CompactionFilterFactory},
Expand All @@ -32,6 +33,7 @@ use crate::{
self, full_merge_callback, partial_merge_callback, MergeFn, MergeOperatorCallback,
},
slice_transform::SliceTransform,
statistics::Ticker,
ColumnFamilyDescriptor, Error, SnapshotWithThreadMode,
};

Expand Down Expand Up @@ -2774,6 +2776,30 @@ impl Options {
}
}

/// StatsLevel can be used to reduce statistics overhead by skipping certain
/// types of stats in the stats collection process.
pub fn set_statistics_level(&self, level: StatsLevel) {
unsafe { ffi::rocksdb_options_set_statistics_level(self.inner, level as c_int) }
}

/// Returns the value of cumulative db counters if stat collection is enabled.
pub fn get_ticker_count(&self, ticker: Ticker) -> u64 {
unsafe { ffi::rocksdb_options_statistics_get_ticker_count(self.inner, ticker as u32) }
}

/// Gets Histogram data from collected db stats. Requires stats to be enabled.
pub fn get_histogram_data(&self, histogram: Histogram) -> HistogramData {
unsafe {
let data = HistogramData::default();
ffi::rocksdb_options_statistics_get_histogram_data(
self.inner,
histogram as u32,
data.inner,
);
data
}
}

/// If not zero, dump `rocksdb.stats` to LOG every `stats_dump_period_sec`.
///
/// Default: `600` (10 mins)
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub mod properties;
mod slice_transform;
mod snapshot;
mod sst_file_writer;
pub mod statistics;
mod transactions;
mod write_batch;

Expand Down

0 comments on commit 5fca3d6

Please sign in to comment.