Removed unnecessary clone.
This commit is contained in:
parent
20b5efcc01
commit
5ad522be43
|
@ -1,6 +1,5 @@
|
||||||
//! This is the main file to house data collection functions.
|
//! This is the main file to house data collection functions.
|
||||||
|
|
||||||
use crate::utils::error::Result;
|
|
||||||
use std::{collections::HashMap, time::Instant};
|
use std::{collections::HashMap, time::Instant};
|
||||||
use sysinfo::{System, SystemExt};
|
use sysinfo::{System, SystemExt};
|
||||||
|
|
||||||
|
@ -11,12 +10,6 @@ pub mod network;
|
||||||
pub mod processes;
|
pub mod processes;
|
||||||
pub mod temperature;
|
pub mod temperature;
|
||||||
|
|
||||||
fn set_if_valid<T: std::clone::Clone>(result: &Result<T>, value_to_set: &mut T) {
|
|
||||||
if let Ok(result) = result {
|
|
||||||
*value_to_set = (*result).clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
pub cpu: cpu::CPUHarvest,
|
pub cpu: cpu::CPUHarvest,
|
||||||
|
@ -69,6 +62,9 @@ pub struct DataState {
|
||||||
mem_total_kb: u64,
|
mem_total_kb: u64,
|
||||||
temperature_type: temperature::TemperatureType,
|
temperature_type: temperature::TemperatureType,
|
||||||
use_current_cpu_total: bool,
|
use_current_cpu_total: bool,
|
||||||
|
last_collection_time: Instant,
|
||||||
|
total_rx: u64,
|
||||||
|
total_tx: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DataState {
|
impl Default for DataState {
|
||||||
|
@ -82,6 +78,9 @@ impl Default for DataState {
|
||||||
mem_total_kb: 0,
|
mem_total_kb: 0,
|
||||||
temperature_type: temperature::TemperatureType::Celsius,
|
temperature_type: temperature::TemperatureType::Celsius,
|
||||||
use_current_cpu_total: false,
|
use_current_cpu_total: false,
|
||||||
|
last_collection_time: Instant::now(),
|
||||||
|
total_rx: 0,
|
||||||
|
total_tx: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,13 +119,16 @@ impl DataState {
|
||||||
// Network
|
// Network
|
||||||
self.data.network = network::get_network_data(
|
self.data.network = network::get_network_data(
|
||||||
&self.sys,
|
&self.sys,
|
||||||
self.data.last_collection_time,
|
self.last_collection_time,
|
||||||
&mut self.data.network.total_rx,
|
&mut self.total_rx,
|
||||||
&mut self.data.network.total_tx,
|
&mut self.total_tx,
|
||||||
current_instant,
|
current_instant,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
self.total_rx = self.data.network.total_rx;
|
||||||
|
self.total_tx = self.data.network.total_tx;
|
||||||
|
|
||||||
// Mem and swap
|
// Mem and swap
|
||||||
if let Ok(memory) = mem::get_mem_data_list().await {
|
if let Ok(memory) = mem::get_mem_data_list().await {
|
||||||
self.data.memory = memory;
|
self.data.memory = memory;
|
||||||
|
@ -154,20 +156,20 @@ impl DataState {
|
||||||
}
|
}
|
||||||
|
|
||||||
// What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update!
|
// What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update!
|
||||||
set_if_valid(
|
if let Ok(process_list) = processes::get_sorted_processes_list(
|
||||||
&processes::get_sorted_processes_list(
|
&self.sys,
|
||||||
&self.sys,
|
&mut self.prev_idle,
|
||||||
&mut self.prev_idle,
|
&mut self.prev_non_idle,
|
||||||
&mut self.prev_non_idle,
|
&mut self.prev_pid_stats,
|
||||||
&mut self.prev_pid_stats,
|
self.use_current_cpu_total,
|
||||||
self.use_current_cpu_total,
|
self.mem_total_kb,
|
||||||
self.mem_total_kb,
|
current_instant,
|
||||||
current_instant,
|
) {
|
||||||
),
|
self.data.list_of_processes = process_list;
|
||||||
&mut self.data.list_of_processes,
|
}
|
||||||
);
|
|
||||||
|
|
||||||
// Update time
|
// Update time
|
||||||
self.data.last_collection_time = current_instant;
|
self.data.last_collection_time = current_instant;
|
||||||
|
self.last_collection_time = current_instant;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ use utils::error::{self, BottomError};
|
||||||
enum Event<I, J> {
|
enum Event<I, J> {
|
||||||
KeyInput(I),
|
KeyInput(I),
|
||||||
MouseInput(J),
|
MouseInput(J),
|
||||||
Update(Box<data_harvester::Data>),
|
Update(data_harvester::Data),
|
||||||
Clean,
|
Clean,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -806,7 +806,8 @@ fn create_event_thread(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
futures::executor::block_on(data_state.update_data());
|
futures::executor::block_on(data_state.update_data());
|
||||||
let event = Event::Update(Box::from(data_state.data.clone()));
|
let event = Event::Update(data_state.data);
|
||||||
|
data_state.data = data_harvester::Data::default();
|
||||||
tx.send(event).unwrap();
|
tx.send(event).unwrap();
|
||||||
thread::sleep(Duration::from_millis(update_rate_in_milliseconds));
|
thread::sleep(Duration::from_millis(update_rate_in_milliseconds));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue