Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose rocksdb cumulative statistics and histograms #853

Merged
merged 2 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -2664,6 +2666,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 {
zaidoon1 marked this conversation as resolved.
Show resolved Hide resolved
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this module be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is how API users can access Ticker enum.

mod transactions;
mod write_batch;

Expand Down