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: {}] mounted on {:?}: {}/{} B",
61 self.name(),
62 self.file_system(),
63 self.kind(),
64 if self.is_removable() { "yes" } else { "no" },
65 self.mount_point(),
66 self.available_space(),
67 self.total_space(),
68 )
69 }
70}
71
72#[cfg(feature = "disk")]
73impl std::fmt::Debug for crate::Disks {
74 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
75 f.debug_list().entries(self.iter()).finish()
76 }
77}
78
79#[cfg(feature = "component")]
80impl std::fmt::Debug for crate::Components {
81 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
82 f.debug_list().entries(self.iter()).finish()
83 }
84}
85
86#[cfg(feature = "component")]
87impl std::fmt::Debug for crate::Component {
88 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89 if let Some(critical) = self.critical() {
90 write!(
91 f,
92 "{}: {}°C (max: {}°C / critical: {}°C)",
93 self.label(),
94 self.temperature(),
95 self.max(),
96 critical
97 )
98 } else {
99 write!(
100 f,
101 "{}: {}°C (max: {}°C)",
102 self.label(),
103 self.temperature(),
104 self.max()
105 )
106 }
107 }
108}
109
110#[cfg(feature = "network")]
111impl std::fmt::Debug for crate::Networks {
112 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113 f.debug_list().entries(self.iter()).finish()
114 }
115}
116
117#[cfg(feature = "network")]
118impl std::fmt::Debug for crate::NetworkData {
119 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
120 f.debug_struct("NetworkData")
121 .field("income", &self.received())
122 .field("total income", &self.total_received())
123 .field("outcome", &self.transmitted())
124 .field("total outcome", &self.total_transmitted())
125 .field("packets income", &self.packets_received())
126 .field("total packets income", &self.total_packets_received())
127 .field("packets outcome", &self.packets_transmitted())
128 .field("total packets outcome", &self.total_packets_transmitted())
129 .field("errors income", &self.errors_on_received())
130 .field("total errors income", &self.total_errors_on_received())
131 .field("errors outcome", &self.errors_on_transmitted())
132 .field("total errors outcome", &self.total_errors_on_transmitted())
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}
154