migrated daemon to tokio with seperate hardware threads + thiserror
This commit is contained in:
+19
-21
@@ -24,7 +24,7 @@ impl HardwareDaemon {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll_fast(&mut self, state: SharedState) {
|
||||
pub async fn poll_fast(&mut self, state: SharedState) {
|
||||
self.sys.refresh_cpu_usage();
|
||||
self.sys.refresh_memory();
|
||||
self.components.refresh(true);
|
||||
@@ -70,23 +70,22 @@ impl HardwareDaemon {
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(mut state_lock) = state.write() {
|
||||
state_lock.cpu.usage = cpu_usage as f64;
|
||||
state_lock.cpu.temp = cpu_temp;
|
||||
state_lock.cpu.model = cpu_model;
|
||||
let mut state_lock = state.write().await;
|
||||
state_lock.cpu.usage = cpu_usage as f64;
|
||||
state_lock.cpu.temp = cpu_temp;
|
||||
state_lock.cpu.model = cpu_model;
|
||||
|
||||
state_lock.memory.total_gb = total_mem;
|
||||
state_lock.memory.used_gb = used_mem;
|
||||
state_lock.memory.total_gb = total_mem;
|
||||
state_lock.memory.used_gb = used_mem;
|
||||
|
||||
state_lock.sys.load_1 = load_avg.one;
|
||||
state_lock.sys.load_5 = load_avg.five;
|
||||
state_lock.sys.load_15 = load_avg.fifteen;
|
||||
state_lock.sys.uptime = uptime;
|
||||
state_lock.sys.process_count = process_count;
|
||||
}
|
||||
state_lock.sys.load_1 = load_avg.one;
|
||||
state_lock.sys.load_5 = load_avg.five;
|
||||
state_lock.sys.load_15 = load_avg.fifteen;
|
||||
state_lock.sys.uptime = uptime;
|
||||
state_lock.sys.process_count = process_count;
|
||||
}
|
||||
|
||||
pub fn poll_slow(&mut self, state: SharedState) {
|
||||
pub async fn poll_slow(&mut self, state: SharedState) {
|
||||
// 1. Gather GPU data outside of lock
|
||||
let mut gpu_state = crate::state::GpuState::default();
|
||||
self.gpu_poll_counter = (self.gpu_poll_counter + 1) % 5;
|
||||
@@ -113,14 +112,13 @@ impl HardwareDaemon {
|
||||
}
|
||||
|
||||
// 3. Apply to state
|
||||
if let Ok(mut state_lock) = state.write() {
|
||||
if should_poll_gpu {
|
||||
state_lock.gpu = gpu_state;
|
||||
}
|
||||
let mut state_lock = state.write().await;
|
||||
if should_poll_gpu {
|
||||
state_lock.gpu = gpu_state;
|
||||
}
|
||||
|
||||
if let Some(d) = disks_data {
|
||||
state_lock.disks = d;
|
||||
}
|
||||
if let Some(d) = disks_data {
|
||||
state_lock.disks = d;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user