diff options
author | ClementTsang <cjhtsang@uwaterloo.ca> | 2020-02-14 22:46:13 -0500 |
---|---|---|
committer | ClementTsang <cjhtsang@uwaterloo.ca> | 2020-02-14 22:51:20 -0500 |
commit | e05b5c46fe12297814346688fc1f2eaa5e9c9737 (patch) | |
tree | dd0e8c5d9779290698bc1577435d9ea05dcb6c0d /src/app/data_harvester.rs | |
parent | aca6c268abf35b8c985b579b35a7f460453b31a3 (diff) |
Merged async together.
Diffstat (limited to 'src/app/data_harvester.rs')
-rw-r--r-- | src/app/data_harvester.rs | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs index 7312e3dc..db07cf41 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester.rs @@ -114,59 +114,68 @@ impl DataState { let current_instant = std::time::Instant::now(); - // TODO: [OPT] MT/Async the harvesting step. + debug!("Start...."); + self.data.cpu = cpu::get_cpu_data_list(&self.sys); + if let Ok(process_list) = processes::get_sorted_processes_list( + &self.sys, + &mut self.prev_idle, + &mut self.prev_non_idle, + &mut self.prev_pid_stats, + self.use_current_cpu_total, + self.mem_total_kb, + current_instant, + ) { + self.data.list_of_processes = process_list; + } - // Network - self.data.network = network::get_network_data( + // ASYNC + let network_data_fut = network::get_network_data( &self.sys, self.last_collection_time, &mut self.total_rx, &mut self.total_tx, current_instant, - ) - .await; - + ); + + let mem_data_fut = mem::get_mem_data_list(); + let swap_data_fut = mem::get_swap_data_list(); + let disk_data_fut = disks::get_disk_usage_list(); + let disk_io_usage_fut = disks::get_io_usage_list(false); + let temp_data_fut = temperature::get_temperature_data(&self.sys, &self.temperature_type); + + let (net_data, mem_res, swap_res, disk_res, io_res, temp_res) = join!( + network_data_fut, + mem_data_fut, + swap_data_fut, + disk_data_fut, + disk_io_usage_fut, + temp_data_fut + ); + + // After async + self.data.network = net_data; self.total_rx = self.data.network.total_rx; self.total_tx = self.data.network.total_tx; - // Mem and swap - if let Ok(memory) = mem::get_mem_data_list().await { + if let Ok(memory) = mem_res { self.data.memory = memory; } - if let Ok(swap) = mem::get_swap_data_list().await { + if let Ok(swap) = swap_res { self.data.swap = swap; } - // CPU - self.data.cpu = cpu::get_cpu_data_list(&self.sys); - - // Disks - if let Ok(disks) = disks::get_disk_usage_list().await { + if let Ok(disks) = disk_res { self.data.disks = disks; } - if let Ok(io) = disks::get_io_usage_list(false).await { + if let Ok(io) = io_res { self.data.io = io; } - // Temp - if let Ok(temp) = temperature::get_temperature_data(&self.sys, &self.temperature_type).await - { + if let Ok(temp) = temp_res { self.data.temperature_sensors = temp; } - - // What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update! - if let Ok(process_list) = processes::get_sorted_processes_list( - &self.sys, - &mut self.prev_idle, - &mut self.prev_non_idle, - &mut self.prev_pid_stats, - self.use_current_cpu_total, - self.mem_total_kb, - current_instant, - ) { - self.data.list_of_processes = process_list; - } + debug!("End...."); // Update time self.data.last_collection_time = current_instant; |