Skip to content

Commit

Permalink
πŸ’„ display bars to visualize cpu core usage
Browse files Browse the repository at this point in the history
  • Loading branch information
friedow committed Apr 1, 2024
1 parent edf66fb commit e2bd47a
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions client/src/plugin/resource_monitor/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down

0 comments on commit e2bd47a

Please sign in to comment.