Add clock wrapper class

This commit is contained in:
Nils Andreas Svee committed 2022-10-15 13:44:30 +02:00
1 parent f7bbb32788
commit c1286b0ba9
7 files changed
+67 -45

No files matched your search

-14
View File
@@ -1,13 +1,3 @@
use nix::errno::Errno;
use nix::time::{clock_gettime, ClockId};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum UtilError {
#[error("libc error")]
Libc(#[from] Errno),
}
pub struct Utils {}
impl Utils {
@@ -17,8 +7,4 @@ impl Utils {
pub fn ewma_factor(tick: f64, dur: f64) -> f64 {
((0.5_f64).ln() / (dur / tick)).exp()
}
pub fn get_current_time() -> Result<(f64, f64), UtilError> {
let time = clock_gettime(ClockId::CLOCK_MONOTONIC)?;
Ok((time.tv_sec() as f64, time.tv_nsec() as f64))
}
}