1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use std::time::Duration;
/// Commit latencies info.
///
/// Contains information about latency of commit stages.
/// Inner struct stores this info in 1/65536 of seconds units.
#[derive(Debug, Clone, Copy)]
#[repr(transparent)]
pub struct CommitLatency(ffi::MDBX_commit_latency);
impl CommitLatency {
/// Create a new `CommitLatency` with zero'd inner struct `ffi::MDBX_commit_latency`.
pub(crate) const fn new() -> Self {
unsafe { Self(std::mem::zeroed()) }
}
/// Returns a mut pointer to `ffi::MDBX_commit_latency`.
pub(crate) const fn mdb_commit_latency(&mut self) -> *mut ffi::MDBX_commit_latency {
&mut self.0
}
}
impl CommitLatency {
/// 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 update by wall clock.
#[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)
}
#[inline]
const fn time_to_duration(time: u32) -> Duration {
Duration::from_nanos(time as u64 * (1_000_000_000 / 65_536))
}
}