sysinfo/
debug.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Take a look at the license at the top of the repository in the LICENSE file.

#[cfg(feature = "system")]
impl std::fmt::Debug for crate::Cpu {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Cpu")
            .field("name", &self.name())
            .field("CPU usage", &self.cpu_usage())
            .field("frequency", &self.frequency())
            .field("vendor ID", &self.vendor_id())
            .field("brand", &self.brand())
            .finish()
    }
}

#[cfg(feature = "system")]
impl std::fmt::Debug for crate::System {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("System")
            .field("global CPU usage", &self.global_cpu_usage())
            .field("load average", &Self::load_average())
            .field("total memory", &self.total_memory())
            .field("free memory", &self.free_memory())
            .field("total swap", &self.total_swap())
            .field("free swap", &self.free_swap())
            .field("nb CPUs", &self.cpus().len())
            .field("nb processes", &self.processes().len())
            .finish()
    }
}

#[cfg(feature = "system")]
impl std::fmt::Debug for crate::Process {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Process")
            .field("pid", &self.pid())
            .field("parent", &self.parent())
            .field("name", &self.name())
            .field("environ", &self.environ())
            .field("command", &self.cmd())
            .field("executable path", &self.exe())
            .field("current working directory", &self.cwd())
            .field("memory usage", &self.memory())
            .field("virtual memory usage", &self.virtual_memory())
            .field("CPU usage", &self.cpu_usage())
            .field("status", &self.status())
            .field("root", &self.root())
            .field("disk_usage", &self.disk_usage())
            .field("user_id", &self.user_id())
            .field("effective_user_id", &self.effective_user_id())
            .finish()
    }
}

#[cfg(feature = "disk")]
impl std::fmt::Debug for crate::Disk {
    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            fmt,
            "Disk({:?})[FS: {:?}][Type: {:?}][removable: {}][I/O: {:?}] mounted on {:?}: {}/{} B",
            self.name(),
            self.file_system(),
            self.kind(),
            if self.is_removable() { "yes" } else { "no" },
            self.usage(),
            self.mount_point(),
            self.available_space(),
            self.total_space(),
        )
    }
}

#[cfg(feature = "disk")]
impl std::fmt::Debug for crate::Disks {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_list().entries(self.iter()).finish()
    }
}

#[cfg(feature = "component")]
impl std::fmt::Debug for crate::Components {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_list().entries(self.iter()).finish()
    }
}

#[cfg(feature = "component")]
impl std::fmt::Debug for crate::Component {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{} ", self.label())?;
        if let Some(temperature) = self.temperature() {
            write!(f, "temperature: {temperature}°C (")?;
        } else {
            f.write_str("temperature: unknown (")?;
        }
        if let Some(max) = self.max() {
            write!(f, "max: {max}°C / ")?;
        } else {
            f.write_str("max: unknown / ")?;
        }
        if let Some(critical) = self.critical() {
            write!(f, "critical: {critical}°C)")
        } else {
            f.write_str("critical: unknown)")
        }
    }
}

#[cfg(feature = "network")]
impl std::fmt::Debug for crate::Networks {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_list().entries(self.iter()).finish()
    }
}

#[cfg(feature = "network")]
impl std::fmt::Debug for crate::NetworkData {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("NetworkData")
            .field("income", &self.received())
            .field("total income", &self.total_received())
            .field("outcome", &self.transmitted())
            .field("total outcome", &self.total_transmitted())
            .field("packets income", &self.packets_received())
            .field("total packets income", &self.total_packets_received())
            .field("packets outcome", &self.packets_transmitted())
            .field("total packets outcome", &self.total_packets_transmitted())
            .field("errors income", &self.errors_on_received())
            .field("total errors income", &self.total_errors_on_received())
            .field("errors outcome", &self.errors_on_transmitted())
            .field("total errors outcome", &self.total_errors_on_transmitted())
            .field("maximum transfer unit", &self.mtu())
            .finish()
    }
}

#[cfg(feature = "user")]
impl std::fmt::Debug for crate::Users {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_list().entries(self.iter()).finish()
    }
}

#[cfg(feature = "user")]
impl std::fmt::Debug for crate::User {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("User")
            .field("uid", &self.id())
            .field("gid", &self.group_id())
            .field("name", &self.name())
            .finish()
    }
}