bug: add extra check for process cpu value to be >= 0

This commit is contained in:
ClementTsang 2020-05-13 00:14:54 -04:00
parent 4831ec3d5c
commit 549d61b836
3 changed files with 61 additions and 56 deletions

View File

@ -288,8 +288,7 @@ pub fn linux_get_processes_list(
.output()?;
let ps_stdout = String::from_utf8_lossy(&ps_result.stdout);
let split_string = ps_stdout.split('\n');
let cpu_calc = cpu_usage_calculation(prev_idle, prev_non_idle);
if let Ok((cpu_usage, cpu_fraction)) = cpu_calc {
if let Ok((cpu_usage, cpu_fraction)) = cpu_usage_calculation(prev_idle, prev_non_idle) {
let process_list = split_string.collect::<Vec<&str>>();
let mut new_pid_stats = HashMap::new();
@ -362,7 +361,9 @@ pub fn windows_macos_get_processes_list(
} else {
process_val.cpu_usage() as f64 / num_cpus
};
let process_cpu_usage = if use_current_cpu_total {
let process_cpu_usage = if pcu < 0.0 {
0.0
} else if use_current_cpu_total {
pcu / cpu_usage
} else {
pcu

View File

@ -141,7 +141,8 @@ impl NetworkGraphWidget for Painter {
Marker::Braille
})
.style(self.colours.rx_style)
.data(&network_data_rx).graph_type(tui::widgets::GraphType::Line),
.data(&network_data_rx)
.graph_type(tui::widgets::GraphType::Line),
);
ret_val.push(
@ -153,7 +154,8 @@ impl NetworkGraphWidget for Painter {
Marker::Braille
})
.style(self.colours.tx_style)
.data(&network_data_tx).graph_type(tui::widgets::GraphType::Line),
.data(&network_data_tx)
.graph_type(tui::widgets::GraphType::Line),
);
ret_val.push(
Dataset::default()
@ -186,7 +188,8 @@ impl NetworkGraphWidget for Painter {
Marker::Braille
})
.style(self.colours.rx_style)
.data(&network_data_rx).graph_type(tui::widgets::GraphType::Line),
.data(&network_data_rx)
.graph_type(tui::widgets::GraphType::Line),
);
ret_val.push(
@ -198,7 +201,8 @@ impl NetworkGraphWidget for Painter {
Marker::Braille
})
.style(self.colours.tx_style)
.data(&network_data_tx).graph_type(tui::widgets::GraphType::Line),
.data(&network_data_tx)
.graph_type(tui::widgets::GraphType::Line),
);
ret_val