-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose commit latency struct for profiling
- Loading branch information
Showing
4 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::{mem, time::Duration}; | ||
|
||
/// Latency statistics for committing transactions. | ||
#[derive(Debug)] | ||
pub struct CommitLatency(pub(crate) ffi::MDBX_commit_latency); | ||
|
||
impl CommitLatency { | ||
pub fn new() -> Self { | ||
unsafe { Self(mem::zeroed()) } | ||
} | ||
|
||
/// Duration of preparation (commit child transactions, update | ||
/// sub-databases records and cursors destroying). | ||
#[inline] | ||
pub const fn preparation(&self) -> Duration { | ||
Self::time_to_duration(self.0.preparation) | ||
} | ||
|
||
/// Duration of GC/freeDB handling & updation. | ||
#[inline] | ||
pub const fn gc_wallclock(&self) -> Duration { | ||
Self::time_to_duration(self.0.gc_wallclock) | ||
} | ||
|
||
/// Duration of internal audit if enabled. | ||
#[inline] | ||
pub const fn audit(&self) -> Duration { | ||
Self::time_to_duration(self.0.audit) | ||
} | ||
|
||
/// Duration of writing dirty/modified data pages to a filesystem, | ||
/// i.e. the summary duration of a `write()` syscalls during commit. | ||
#[inline] | ||
pub const fn write(&self) -> Duration { | ||
Self::time_to_duration(self.0.write) | ||
} | ||
|
||
/// Duration of syncing written data to the disk/storage, i.e. | ||
/// the duration of a `fdatasync()` or a `msync()` syscall during commit. | ||
#[inline] | ||
pub const fn sync(&self) -> Duration { | ||
Self::time_to_duration(self.0.sync) | ||
} | ||
|
||
/// Duration of transaction ending (releasing resources). | ||
#[inline] | ||
pub const fn ending(&self) -> Duration { | ||
Self::time_to_duration(self.0.ending) | ||
} | ||
|
||
/// The total duration of a commit. | ||
#[inline] | ||
pub const fn whole(&self) -> Duration { | ||
Self::time_to_duration(self.0.whole) | ||
} | ||
|
||
/// User-mode CPU time spent on GC update. | ||
#[inline] | ||
pub const fn gc_cputime(&self) -> Duration { | ||
Self::time_to_duration(self.0.gc_cputime) | ||
} | ||
|
||
/// Latency of commit stages in 1/65_536 of seconds units. | ||
#[inline] | ||
const fn time_to_duration(time: u32) -> Duration { | ||
Duration::from_nanos(time as u64 * (1_000_000_000 / 65_536)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ mod cursor; | |
mod database; | ||
mod error; | ||
mod flags; | ||
mod latency; | ||
mod table; | ||
mod transaction; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters