psutil/cpu/os/
linux.rs

1use std::time::Duration;
2
3use crate::cpu::{CpuTimes, CpuTimesPercent};
4use crate::Percent;
5
6pub trait CpuTimesExt {
7	/// Time spent waiting for I/O to complete.
8	/// This is *not* accounted in idle time counter.
9	fn iowait(&self) -> Duration;
10
11	/// Time spent for servicing hardware interrupts.
12	fn irq(&self) -> Duration;
13
14	/// Time spent for servicing software interrupts.
15	fn softirq(&self) -> Duration;
16
17	/// Time spent by other operating systems running in a virtualized environment.
18	fn steal(&self) -> Option<Duration>;
19
20	/// Time spent running a virtual CPU for guest operating systems
21	/// under the control of the Linux kernel.
22	fn guest(&self) -> Option<Duration>;
23
24	/// Time spent running a niced guest
25	/// (virtual CPU for guest operating systems
26	/// under the control of the Linux kernel).
27	fn guest_nice(&self) -> Option<Duration>;
28}
29
30impl CpuTimesExt for CpuTimes {
31	fn iowait(&self) -> Duration {
32		self.iowait
33	}
34
35	fn irq(&self) -> Duration {
36		self.irq
37	}
38
39	fn softirq(&self) -> Duration {
40		self.softirq
41	}
42
43	fn steal(&self) -> Option<Duration> {
44		self.steal
45	}
46
47	fn guest(&self) -> Option<Duration> {
48		self.guest
49	}
50
51	fn guest_nice(&self) -> Option<Duration> {
52		self.guest_nice
53	}
54}
55
56pub trait CpuTimesPercentExt {
57	/// Time spent waiting for I/O to complete.
58	/// This is *not* accounted in idle time counter.
59	fn iowait(&self) -> Percent;
60
61	/// Time spent for servicing hardware interrupts.
62	fn irq(&self) -> Percent;
63
64	/// Time spent for servicing software interrupts.
65	fn softirq(&self) -> Percent;
66
67	/// Time spent by other operating systems running in a virtualized environment.
68	fn steal(&self) -> Option<Percent>;
69
70	/// Time spent running a virtual CPU for guest operating systems
71	/// under the control of the Linux kernel.
72	fn guest(&self) -> Option<Percent>;
73
74	/// Time spent running a niced guest
75	/// (virtual CPU for guest operating systems
76	/// under the control of the Linux kernel).
77	fn guest_nice(&self) -> Option<Percent>;
78}
79
80impl CpuTimesPercentExt for CpuTimesPercent {
81	fn iowait(&self) -> Percent {
82		self.iowait
83	}
84
85	fn irq(&self) -> Percent {
86		self.irq
87	}
88
89	fn softirq(&self) -> Percent {
90		self.softirq
91	}
92
93	fn steal(&self) -> Option<Percent> {
94		self.steal
95	}
96
97	fn guest(&self) -> Option<Percent> {
98		self.guest
99	}
100
101	fn guest_nice(&self) -> Option<Percent> {
102		self.guest_nice
103	}
104}