Added RAM values to chart.

This commit is contained in:
ClementTsang 2019-10-03 00:05:58 -04:00
parent 15f14be0b2
commit 11f8b8ea2b
3 changed files with 40 additions and 4 deletions

View File

@ -31,6 +31,7 @@ pub struct CanvasData {
pub temp_sensor_data : Vec<Vec<String>>,
pub process_data : Vec<Vec<String>>,
pub mem_data : Vec<(f64, f64)>,
pub mem_values : Vec<(u64, u64)>,
pub swap_data : Vec<(f64, f64)>,
pub cpu_data : Vec<(String, Vec<(f64, f64)>)>,
}
@ -130,8 +131,15 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
.style(Style::default().fg(GRAPH_COLOUR))
.bounds([-0.5, 100.5])
.labels(&["0%", "100%"]); // Offset as the zero value isn't drawn otherwise...
let mem_name = "RAM:".to_string() + &format!("{:3}%", (canvas_data.mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64));
let swap_name = "SWP:".to_string() + &format!("{:3}%", (canvas_data.swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64));
let mem_name = "RAM:".to_string()
+ &format!("{:3}%", (canvas_data.mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64))
+ &format!(
" {:.1}GB/{:.1}GB",
canvas_data.mem_values[0].0 as f64 / 1024.0,
canvas_data.mem_values[0].1 as f64 / 1024.0
);
let swap_name;
let mut mem_canvas_vec : Vec<Dataset> = vec![Dataset::default()
.name(&mem_name)
@ -140,6 +148,13 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
.data(&canvas_data.mem_data)];
if !(&canvas_data.swap_data).is_empty() && (&canvas_data.swap_data).last().unwrap().1 >= 0.0 {
swap_name = "SWP:".to_string()
+ &format!("{:3}%", (canvas_data.swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64))
+ &format!(
" {:.1}GB/{:.1}GB",
canvas_data.mem_values[1].0 as f64 / 1024.0,
canvas_data.mem_values[1].1 as f64 / 1024.0
);
mem_canvas_vec.push(
Dataset::default()
.name(&swap_name)

View File

@ -184,7 +184,28 @@ pub fn update_swap_data_points(app_data : &data_collection::Data) -> Vec<(f64, f
convert_mem_data(&app_data.swap)
}
pub fn convert_mem_data(mem_data : &[data_collection::mem::MemData]) -> Vec<(f64, f64)> {
pub fn update_mem_data_values(app_data : &data_collection::Data) -> Vec<(u64, u64)> {
let mut result : Vec<(u64, u64)> = Vec::new();
result.push(get_most_recent_mem_values(&app_data.memory));
result.push(get_most_recent_mem_values(&app_data.swap));
result
}
fn get_most_recent_mem_values(mem_data : &[data_collection::mem::MemData]) -> (u64, u64) {
let mut result : (u64, u64) = (0, 0);
if !mem_data.is_empty() {
if let Some(most_recent) = mem_data.last() {
result.0 = most_recent.mem_used_in_mb;
result.1 = most_recent.mem_total_in_mb;
}
}
result
}
fn convert_mem_data(mem_data : &[data_collection::mem::MemData]) -> Vec<(f64, f64)> {
let mut result : Vec<(f64, f64)> = Vec::new();
for data in mem_data {
@ -211,7 +232,6 @@ pub fn convert_mem_data(mem_data : &[data_collection::mem::MemData]) -> Vec<(f64
}
result.push(new_entry);
//debug!("Pushed: ({}, {})", result.last().unwrap().0, result.last().unwrap().1);
}
result

View File

@ -241,6 +241,7 @@ fn main() -> error::Result<()> {
canvas_data.temp_sensor_data = update_temp_row(&app.data, &app.temperature_type);
canvas_data.process_data = update_process_row(&app.data);
canvas_data.mem_data = update_mem_data_points(&app.data);
canvas_data.mem_values = update_mem_data_values(&app.data);
canvas_data.swap_data = update_swap_data_points(&app.data);
canvas_data.cpu_data = update_cpu_data_points(app.show_average_cpu, &app.data);