heim_process/process/
cpu_times.rs

1use std::fmt;
2
3use heim_common::prelude::wrap;
4use heim_common::units::Time;
5
6use crate::sys;
7
8/// Accumulated CPU time for specific process.
9pub struct CpuTime(sys::CpuTime);
10
11wrap!(CpuTime, sys::CpuTime);
12
13impl CpuTime {
14    /// Returns amount of CPU time spent in user mode within the process.
15    pub fn user(&self) -> Time {
16        self.as_ref().user()
17    }
18
19    /// Returns amount of CPU time spent in kernel within the process.
20    pub fn system(&self) -> Time {
21        self.as_ref().system()
22    }
23}
24
25impl fmt::Debug for CpuTime {
26    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27        f.debug_struct("CpuTime")
28            .field("user", &self.user())
29            .field("system", &self.system())
30            .finish()
31    }
32}