From 9d6a71d479902bce52615804ddb4116f598d9576 Mon Sep 17 00:00:00 2001 From: jackra1n Date: Thu, 16 Nov 2023 18:09:16 +0100 Subject: [PATCH] Try reduce cpu usage --- src/main.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 634755d..0bff410 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use embedded_graphics::{ use std::error::Error; use std::fs; use std::thread; -use std::time::Duration; +use std::time::{Duration, Instant}; use sysinfo::{System, SystemExt, CpuExt, DiskExt}; use machine_ip; @@ -17,13 +17,22 @@ fn main() -> Result<(), Box> { let mut disp = initialize_display()?; let mut sys: System = SystemExt::new_all(); + let mut last_disk_update = Instant::now(); + let disk_update_interval = Duration::from_secs(60); + loop { - sys.refresh_all(); + sys.refresh_cpu(); + sys.refresh_memory(); - let temp = get_cpu_temperature()?; + let temp = get_cpu_temperature(); let ip_address = get_local_ip(); let cpu_usage = get_cpu_usage(&sys); let ram_usage = get_ram_usage(&sys); + + if last_disk_update.elapsed() >= disk_update_interval { + sys.refresh_disks(); + last_disk_update = Instant::now(); + } let disk_usage = get_disk_usage(&sys); update_display(&mut disp, &ip_address, &cpu_usage, temp, ram_usage, disk_usage)?;