1use crate::{
4 Component, Components, Cpu, Disk, Disks, NetworkData, Networks, Process, System, User, Users,
5};
6
7use std::fmt;
8
9impl fmt::Debug for Cpu {
10 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11 f.debug_struct("Cpu")
12 .field("name", &self.name())
13 .field("CPU usage", &self.cpu_usage())
14 .field("frequency", &self.frequency())
15 .field("vendor ID", &self.vendor_id())
16 .field("brand", &self.brand())
17 .finish()
18 }
19}
20
21impl fmt::Debug for System {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 f.debug_struct("System")
24 .field("global CPU usage", &self.global_cpu_info().cpu_usage())
25 .field("load average", &Self::load_average())
26 .field("total memory", &self.total_memory())
27 .field("free memory", &self.free_memory())
28 .field("total swap", &self.total_swap())
29 .field("free swap", &self.free_swap())
30 .field("nb CPUs", &self.cpus().len())
31 .field("nb processes", &self.processes().len())
32 .finish()
33 }
34}
35
36impl fmt::Debug for Disk {
37 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
38 write!(
39 fmt,
40 "Disk({:?})[FS: {:?}][Type: {:?}][removable: {}] mounted on {:?}: {}/{} B",
41 self.name(),
42 self.file_system(),
43 self.kind(),
44 if self.is_removable() { "yes" } else { "no" },
45 self.mount_point(),
46 self.available_space(),
47 self.total_space(),
48 )
49 }
50}
51
52impl fmt::Debug for Process {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 f.debug_struct("Process")
55 .field("pid", &self.pid())
56 .field("parent", &self.parent())
57 .field("name", &self.name())
58 .field("environ", &self.environ())
59 .field("command", &self.cmd())
60 .field("executable path", &self.exe())
61 .field("current working directory", &self.cwd())
62 .field("memory usage", &self.memory())
63 .field("virtual memory usage", &self.virtual_memory())
64 .field("CPU usage", &self.cpu_usage())
65 .field("status", &self.status())
66 .field("root", &self.root())
67 .field("disk_usage", &self.disk_usage())
68 .field("user_id", &self.user_id())
69 .field("effective_user_id", &self.effective_user_id())
70 .finish()
71 }
72}
73
74impl fmt::Debug for Components {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76 write!(
77 f,
78 "Components {{ {} }}",
79 self.iter()
80 .map(|x| format!("{x:?}"))
81 .collect::<Vec<_>>()
82 .join(", ")
83 )
84 }
85}
86
87impl fmt::Debug for Component {
88 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> 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
110impl fmt::Debug for Networks {
111 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112 write!(
113 f,
114 "Networks {{ {} }}",
115 self.iter()
116 .map(|x| format!("{x:?}"))
117 .collect::<Vec<_>>()
118 .join(", ")
119 )
120 }
121}
122
123impl fmt::Debug for NetworkData {
124 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
125 f.debug_struct("NetworkData")
126 .field("income", &self.received())
127 .field("total income", &self.total_received())
128 .field("outcome", &self.transmitted())
129 .field("total outcome", &self.total_transmitted())
130 .field("packets income", &self.packets_received())
131 .field("total packets income", &self.total_packets_received())
132 .field("packets outcome", &self.packets_transmitted())
133 .field("total packets outcome", &self.total_packets_transmitted())
134 .field("errors income", &self.errors_on_received())
135 .field("total errors income", &self.total_errors_on_received())
136 .field("errors outcome", &self.errors_on_transmitted())
137 .field("total errors outcome", &self.total_errors_on_transmitted())
138 .finish()
139 }
140}
141
142impl fmt::Debug for Disks {
143 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
144 write!(
145 f,
146 "Disks {{ {} }}",
147 self.iter()
148 .map(|x| format!("{x:?}"))
149 .collect::<Vec<_>>()
150 .join(", ")
151 )
152 }
153}
154
155impl fmt::Debug for Users {
156 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157 write!(
158 f,
159 "Users {{ {} }}",
160 self.iter()
161 .map(|x| format!("{x:?}"))
162 .collect::<Vec<_>>()
163 .join(", ")
164 )
165 }
166}
167
168impl fmt::Debug for User {
169 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
170 f.debug_struct("User")
171 .field("uid", &self.id())
172 .field("gid", &self.group_id())
173 .field("name", &self.name())
174 .finish()
175 }
176}