heim_cpu/os/linux/times.rs
1use heim_common::units::Time;
2
3/// Linux-specific extension for [CpuTime].
4///
5/// [CpuTime]: ../../struct.CpuTime.html
6pub trait CpuTimeExt {
7 /// Returns time spent by niced (prioritized) processes executing in user mode,
8 /// this also includes [guest_nice] time.
9 ///
10 /// [guest_nice]: #tymethod.guest_nice
11 fn nice(&self) -> Time;
12
13 /// Returns time spent waiting for I/O to complete.
14 fn io_wait(&self) -> Time;
15
16 /// Returns time spent for servicing hardware interrupts.
17 fn irq(&self) -> Time;
18
19 /// Returns time spent for servicing software interrupts.
20 fn soft_irq(&self) -> Time;
21
22 /// Returns time spent by other operating systems running in a virtualized environment.
23 fn steal(&self) -> Time;
24
25 /// Returns time spent running a virtual CPU for guest operating systems
26 /// under the control of the Linux kernel.
27 ///
28 /// ## Compatibility
29 ///
30 /// Available for Linux 2.6.24+, older versions always returns `None`.
31 fn guest(&self) -> Option<Time>;
32
33 /// Returns time spent running a niced guest
34 /// (virtual CPU for guest operating systems under the control of the Linux kernel)
35 ///
36 /// ## Compatibility
37 ///
38 /// Available for Linux 3.2.0+, older versions always returns `None`.
39 fn guest_nice(&self) -> Option<Time>;
40}
41
42impl CpuTimeExt for crate::CpuTime {
43 fn nice(&self) -> Time {
44 self.as_ref().nice()
45 }
46
47 fn io_wait(&self) -> Time {
48 self.as_ref().io_wait()
49 }
50
51 fn irq(&self) -> Time {
52 self.as_ref().irq()
53 }
54
55 fn soft_irq(&self) -> Time {
56 self.as_ref().soft_irq()
57 }
58
59 fn steal(&self) -> Time {
60 self.as_ref().steal()
61 }
62
63 fn guest(&self) -> Option<Time> {
64 self.as_ref().guest()
65 }
66
67 fn guest_nice(&self) -> Option<Time> {
68 self.as_ref().guest_nice()
69 }
70}