heim_cpu/os/linux/
times.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use heim_common::units::Time;

/// Linux-specific extension for [CpuTime].
///
/// [CpuTime]: ../../struct.CpuTime.html
pub trait CpuTimeExt {
    /// Returns time spent by niced (prioritized) processes executing in user mode,
    /// this also includes [guest_nice] time.
    ///
    /// [guest_nice]: #tymethod.guest_nice
    fn nice(&self) -> Time;

    /// Returns time spent waiting for I/O to complete.
    fn io_wait(&self) -> Time;

    /// Returns time spent for servicing hardware interrupts.
    fn irq(&self) -> Time;

    /// Returns time spent for servicing software interrupts.
    fn soft_irq(&self) -> Time;

    /// Returns time spent by other operating systems running in a virtualized environment.
    fn steal(&self) -> Time;

    /// Returns time spent running a virtual CPU for guest operating systems
    /// under the control of the Linux kernel.
    ///
    /// ## Compatibility
    ///
    /// Available for Linux 2.6.24+, older versions always returns `None`.
    fn guest(&self) -> Option<Time>;

    /// Returns time spent running a niced guest
    /// (virtual CPU for guest operating systems under the control of the Linux kernel)
    ///
    /// ## Compatibility
    ///
    /// Available for Linux 3.2.0+, older versions always returns `None`.
    fn guest_nice(&self) -> Option<Time>;
}

impl CpuTimeExt for crate::CpuTime {
    fn nice(&self) -> Time {
        self.as_ref().nice()
    }

    fn io_wait(&self) -> Time {
        self.as_ref().io_wait()
    }

    fn irq(&self) -> Time {
        self.as_ref().irq()
    }

    fn soft_irq(&self) -> Time {
        self.as_ref().soft_irq()
    }

    fn steal(&self) -> Time {
        self.as_ref().steal()
    }

    fn guest(&self) -> Option<Time> {
        self.as_ref().guest()
    }

    fn guest_nice(&self) -> Option<Time> {
        self.as_ref().guest_nice()
    }
}