mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-30 08:00:20 +00:00
Removed unnecessary clone.
This commit is contained in:
parent
20b5efcc01
commit
5ad522be43
2 changed files with 27 additions and 24 deletions
|
@ -1,6 +1,5 @@
|
|||
//! This is the main file to house data collection functions.
|
||||
|
||||
use crate::utils::error::Result;
|
||||
use std::{collections::HashMap, time::Instant};
|
||||
use sysinfo::{System, SystemExt};
|
||||
|
||||
|
@ -11,12 +10,6 @@ pub mod network;
|
|||
pub mod processes;
|
||||
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)]
|
||||
pub struct Data {
|
||||
pub cpu: cpu::CPUHarvest,
|
||||
|
@ -69,6 +62,9 @@ pub struct DataState {
|
|||
mem_total_kb: u64,
|
||||
temperature_type: temperature::TemperatureType,
|
||||
use_current_cpu_total: bool,
|
||||
last_collection_time: Instant,
|
||||
total_rx: u64,
|
||||
total_tx: u64,
|
||||
}
|
||||
|
||||
impl Default for DataState {
|
||||
|
@ -82,6 +78,9 @@ impl Default for DataState {
|
|||
mem_total_kb: 0,
|
||||
temperature_type: temperature::TemperatureType::Celsius,
|
||||
use_current_cpu_total: false,
|
||||
last_collection_time: Instant::now(),
|
||||
total_rx: 0,
|
||||
total_tx: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,13 +119,16 @@ impl DataState {
|
|||
// Network
|
||||
self.data.network = network::get_network_data(
|
||||
&self.sys,
|
||||
self.data.last_collection_time,
|
||||
&mut self.data.network.total_rx,
|
||||
&mut self.data.network.total_tx,
|
||||
self.last_collection_time,
|
||||
&mut self.total_rx,
|
||||
&mut self.total_tx,
|
||||
current_instant,
|
||||
)
|
||||
.await;
|
||||
|
||||
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 {
|
||||
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!
|
||||
set_if_valid(
|
||||
&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,
|
||||
),
|
||||
&mut self.data.list_of_processes,
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
// Update time
|
||||
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> {
|
||||
KeyInput(I),
|
||||
MouseInput(J),
|
||||
Update(Box<data_harvester::Data>),
|
||||
Update(data_harvester::Data),
|
||||
Clean,
|
||||
}
|
||||
|
||||
|
@ -806,7 +806,8 @@ fn create_event_thread(
|
|||
}
|
||||
}
|
||||
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();
|
||||
thread::sleep(Duration::from_millis(update_rate_in_milliseconds));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue