#[cfg(target_os = "linux")]
use nix::unistd::{getpid, gettid};
#[inline]
pub fn monotonic_timestamp_ns() -> u64 {
#[cfg(target_os = "linux")]
{
use {
nix::time::{ClockId, clock_gettime},
std::time::Duration,
};
let timestamp =
clock_gettime(ClockId::CLOCK_MONOTONIC).expect("CLOCK_MONOTONIC must be available");
Duration::from(timestamp)
.as_nanos()
.try_into()
.expect("monotonic timestamp must fit in u64 nanoseconds")
}
#[cfg(not(target_os = "linux"))]
{
0
}
}
#[inline]
pub fn cached_thread_and_process_id() -> (i32, i32) {
#[cfg(target_os = "linux")]
thread_local! {
static THREAD_AND_PROCESS_ID: (i32, i32) = (gettid().as_raw(), getpid().as_raw());
}
#[cfg(target_os = "linux")]
{
THREAD_AND_PROCESS_ID.with(|thread_and_process_id| *thread_and_process_id)
}
#[cfg(not(target_os = "linux"))]
{
(0, 0)
}
}