From e2bd47adf6d8a102b741b741e893b34435dce73e Mon Sep 17 00:00:00 2001 From: Christian Friedow Date: Mon, 1 Apr 2024 19:26:43 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20display=20bars=20to=20visualize?= =?UTF-8?q?=20cpu=20core=20usage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/plugin/resource_monitor/cpu.rs | 40 +++++++++++++++-------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/client/src/plugin/resource_monitor/cpu.rs b/client/src/plugin/resource_monitor/cpu.rs index f76fde8..f2a04d4 100644 --- a/client/src/plugin/resource_monitor/cpu.rs +++ b/client/src/plugin/resource_monitor/cpu.rs @@ -28,23 +28,37 @@ impl Plugin for CpuPlugin { fn update_entries(&mut self) -> anyhow::Result<()> { self.sysinfo.refresh_cpu(); - self.entries.clear(); + + let mut core_usages: String = format!( + "{}% – {} Cores:", + self.sysinfo.global_cpu_info().cpu_usage() as i32, + self.sysinfo.cpus().len() + ); + for cpu_core in self.sysinfo.cpus() { - self.entries.push(crate::model::Entry { - id: cpu_core.name().to_string(), - title: format!( - "{}: {}% {}MHz", - cpu_core.name(), - cpu_core.cpu_usage() as i32, - cpu_core.frequency() - ), - action: String::from(""), - meta: String::from("Resource Monitor CPU"), - command: None, - }); + let core_usage = match cpu_core.cpu_usage() as i32 { + 0..=12 => " ▁", + 13..=25 => " ▂", + 26..=37 => " ▃", + 38..=50 => " ▄", + 51..=62 => " ▅", + 63..=75 => " ▆", + 76..=87 => " ▇", + _ => " █", + }; + + core_usages.push_str(core_usage); } + self.entries.push(crate::model::Entry { + id: "cpu".into(), + title: core_usages, + action: String::from(""), + meta: String::from("Resource Monitor CPU"), + command: None, + }); + Ok(()) }