Skip to main content

wowlab_sentinel/utils/
sys.rs

1const CPU_SAMPLE_INTERVAL_MS: u64 = 100;
2
3/// Sleeps to measure a delta against system CPU ticks.
4pub(crate) async fn cpu_usage_percent() -> f64 {
5    let Some(before) = wowlab_common::sys::read_cpu_ticks() else {
6        return 0.0;
7    };
8
9    tokio::time::sleep(std::time::Duration::from_millis(CPU_SAMPLE_INTERVAL_MS)).await;
10    let Some(after) = wowlab_common::sys::read_cpu_ticks() else {
11        return 0.0;
12    };
13
14    wowlab_common::sys::cpu_usage_from_ticks(before, after)
15}