feat(agent): add safe lowlevel extension point

This commit is contained in:
igor04091968
2026-06-04 13:08:07 +03:00
parent 313c49eb4e
commit 0341e114a9
5 changed files with 131 additions and 0 deletions
@@ -0,0 +1,36 @@
use std::sync::OnceLock;
use std::time::{Instant, SystemTime, UNIX_EPOCH};
static MONOTONIC_START: OnceLock<Instant> = OnceLock::new();
pub fn monotonic_ticks() -> u128 {
MONOTONIC_START
.get_or_init(Instant::now)
.elapsed()
.as_nanos()
}
pub fn high_precision_time_ns() -> u128 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_nanos()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn monotonic_ticks_do_not_go_backwards() {
let first = monotonic_ticks();
let second = monotonic_ticks();
assert!(second >= first);
}
#[test]
fn high_precision_time_is_epoch_based() {
assert!(high_precision_time_ns() > 1_000_000_000);
}
}