sysinfo/
debug.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#[cfg(feature = "system")]
4impl std::fmt::Debug for crate::Cpu {
5    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6        f.debug_struct("Cpu")
7            .field("name", &self.name())
8            .field("CPU usage", &self.cpu_usage())
9            .field("frequency", &self.frequency())
10            .field("vendor ID", &self.vendor_id())
11            .field("brand", &self.brand())
12            .finish()
13    }
14}
15
16#[cfg(feature = "system")]
17impl std::fmt::Debug for crate::System {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        f.debug_struct("System")
20            .field("global CPU usage", &self.global_cpu_usage())
21            .field("load average", &Self::load_average())
22            .field("total memory", &self.total_memory())
23            .field("free memory", &self.free_memory())
24            .field("total swap", &self.total_swap())
25            .field("free swap", &self.free_swap())
26            .field("nb CPUs", &self.cpus().len())
27            .field("nb processes", &self.processes().len())
28            .finish()
29    }
30}
31
32#[cfg(feature = "system")]
33impl std::fmt::Debug for crate::Process {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        f.debug_struct("Process")
36            .field("pid", &self.pid())
37            .field("parent", &self.parent())
38            .field("name", &self.name())
39            .field("environ", &self.environ())
40            .field("command", &self.cmd())
41            .field("executable path", &self.exe())
42            .field("current working directory", &self.cwd())
43            .field("memory usage", &self.memory())
44            .field("virtual memory usage", &self.virtual_memory())
45            .field("CPU usage", &self.cpu_usage())
46            .field("status", &self.status())
47            .field("root", &self.root())
48            .field("disk_usage", &self.disk_usage())
49            .field("user_id", &self.user_id())
50            .field("effective_user_id", &self.effective_user_id())
51            .finish()
52    }
53}
54
55#[cfg(feature = "disk")]
56impl std::fmt::Debug for crate::Disk {
57    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58        write!(
59            fmt,
60            "Disk({:?})[FS: {:?}][Type: {:?}][removable: {}][I/O: {:?}] mounted on {:?}: {}/{} B",
61            self.name(),
62            self.file_system(),
63            self.kind(),
64            if self.is_removable() { "yes" } else { "no" },
65            self.usage(),
66            self.mount_point(),
67            self.available_space(),
68            self.total_space(),
69        )
70    }
71}
72
73#[cfg(feature = "disk")]
74impl std::fmt::Debug for crate::Disks {
75    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76        f.debug_list().entries(self.iter()).finish()
77    }
78}
79
80#[cfg(feature = "component")]
81impl std::fmt::Debug for crate::Components {
82    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83        f.debug_list().entries(self.iter()).finish()
84    }
85}
86
87#[cfg(feature = "component")]
88impl std::fmt::Debug for crate::Component {
89    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90        write!(f, "{} ", self.label())?;
91        if let Some(temperature) = self.temperature() {
92            write!(f, "temperature: {temperature}°C (")?;
93        } else {
94            f.write_str("temperature: unknown (")?;
95        }
96        if let Some(max) = self.max() {
97            write!(f, "max: {max}°C / ")?;
98        } else {
99            f.write_str("max: unknown / ")?;
100        }
101        if let Some(critical) = self.critical() {
102            write!(f, "critical: {critical}°C)")
103        } else {
104            f.write_str("critical: unknown)")
105        }
106    }
107}
108
109#[cfg(feature = "network")]
110impl std::fmt::Debug for crate::Networks {
111    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
112        f.debug_list().entries(self.iter()).finish()
113    }
114}
115
116#[cfg(feature = "network")]
117impl std::fmt::Debug for crate::NetworkData {
118    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
119        f.debug_struct("NetworkData")
120            .field("income", &self.received())
121            .field("total income", &self.total_received())
122            .field("outcome", &self.transmitted())
123            .field("total outcome", &self.total_transmitted())
124            .field("packets income", &self.packets_received())
125            .field("total packets income", &self.total_packets_received())
126            .field("packets outcome", &self.packets_transmitted())
127            .field("total packets outcome", &self.total_packets_transmitted())
128            .field("errors income", &self.errors_on_received())
129            .field("total errors income", &self.total_errors_on_received())
130            .field("errors outcome", &self.errors_on_transmitted())
131            .field("total errors outcome", &self.total_errors_on_transmitted())
132            .field("maximum transfer unit", &self.mtu())
133            .finish()
134    }
135}
136
137#[cfg(feature = "user")]
138impl std::fmt::Debug for crate::Users {
139    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
140        f.debug_list().entries(self.iter()).finish()
141    }
142}
143
144#[cfg(feature = "user")]
145impl std::fmt::Debug for crate::User {
146    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
147        f.debug_struct("User")
148            .field("uid", &self.id())
149            .field("gid", &self.group_id())
150            .field("name", &self.name())
151            .finish()
152    }
153}