From 1b9e5ab1a09f0ff9c8394a2bdbab4b3147acfc62 Mon Sep 17 00:00:00 2001 From: Janakarajan Natarajan Date: Fri, 10 Mar 2023 17:55:13 +0000 Subject: [PATCH] Visualizer updates Updates: * CPU Utilization graph y-axis is always 100%. * Diskstat read, sector graph updates. * VMStat graph updates. --- src/bin/html_files/cpu_utilization.ts | 1 + src/bin/html_files/perf_stat.ts | 3 --- src/data/constants.rs | 2 ++ src/data/diskstats.rs | 23 +++++++++--------- src/data/vmstat.rs | 34 +++++++++++++++++---------- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/bin/html_files/cpu_utilization.ts b/src/bin/html_files/cpu_utilization.ts index 9f4a8a35..6a8b485e 100644 --- a/src/bin/html_files/cpu_utilization.ts +++ b/src/bin/html_files/cpu_utilization.ts @@ -35,6 +35,7 @@ function getUtilizationType(run, elem, type) { }, yaxis: { title: 'CPU Utilization (%)', + range: [0, 100], }, }; Plotly.newPlot(TESTER, cpu_type_datas, layout, { frameMargins: 0 }); diff --git a/src/bin/html_files/perf_stat.ts b/src/bin/html_files/perf_stat.ts index 3662af62..4d8ea4e9 100644 --- a/src/bin/html_files/perf_stat.ts +++ b/src/bin/html_files/perf_stat.ts @@ -44,7 +44,6 @@ function getEvent(run, key, parent_id) { http.onload = function () { var data = JSON.parse(http.response); var perfstat_datas = []; - console.log(data); data[0].cpus.forEach(function (value, index, arr) { var cpu_stat = new StatValue(); cpu_stat.cpu = value.cpu; @@ -52,13 +51,11 @@ function getEvent(run, key, parent_id) { cpu_stat.y_data = []; perfstat_datas.push(cpu_stat); }); - console.log(perfstat_datas); data.forEach(function (value, index, arr) { value.cpus.forEach(function (stat, i_index, i_arr) { addData(perfstat_datas, stat, value.time.TimeDiff); }) }); - console.log(perfstat_datas); var elem = document.createElement('div'); elem.style.float = "none"; addElemToNode(parent_id, elem); diff --git a/src/data/constants.rs b/src/data/constants.rs index b0a68fc0..1013ca47 100644 --- a/src/data/constants.rs +++ b/src/data/constants.rs @@ -2,3 +2,5 @@ pub static KB_FACTOR: u64 = 1024; pub static MB_FACTOR: u64 = 1048576; pub static TIME_S_FACTOR: u64 = 1000; pub static FACTOR_OF_ONE: u64 = 1; +pub static MULT_FACTOR_OF_ONE: u64 = 1; +pub static MULT_SECTORS: u64 = 512; diff --git a/src/data/diskstats.rs b/src/data/diskstats.rs index 0e84e7f5..1fd56b16 100644 --- a/src/data/diskstats.rs +++ b/src/data/diskstats.rs @@ -212,17 +212,22 @@ fn get_disk_names(value: Diskstats) -> Vec { fn get_values(values: Vec, key: String, unit: String) -> Result { let mut ev: BTreeMap = BTreeMap::new(); let disk_names = get_disk_names(values[0].clone()); - let mut factor = KB_FACTOR; + let mut factor = FACTOR_OF_ONE; + let mut mult_factor = MULT_FACTOR_OF_ONE; for name in disk_names { let dv = DiskValues::new(name.clone()); ev.insert(name, dv); } + if key.contains("Time") { factor = TIME_S_FACTOR; - } else if "MB" == unit { - factor = MB_FACTOR; - } else if key.contains("Merged") { - factor = FACTOR_OF_ONE; + } + if key.contains("Sectors") { + mult_factor = MULT_SECTORS; + factor = KB_FACTOR; + if unit == "MB" { + factor = MB_FACTOR; + } } let time_zero = values[0].time; let mut prev_data = values[0].clone(); @@ -240,7 +245,7 @@ fn get_values(values: Vec, key: String, unit: String) -> Result Result { for key in DiskstatKeys::iter() { let mut unit: String = "Count".to_string(); if key.to_string().contains("Sectors") { - unit = "Sectors".to_string(); + unit = format!("{} ({})", "Sectors", user_unit); } else if key.to_string().contains("Time") { unit = "Time (s)".to_string(); - } else if key.to_string().contains("Merged") { - unit = "Merges (Count)".to_string(); - } else if !key.to_string().contains("In Progress") { - unit = format!("{} ({})", key, user_unit); } end_values.push(Key {name: key.to_string(), unit: unit}); } diff --git a/src/data/vmstat.rs b/src/data/vmstat.rs index 08e53ea0..ae3f303a 100644 --- a/src/data/vmstat.rs +++ b/src/data/vmstat.rs @@ -70,20 +70,30 @@ struct VmstatEntry { fn get_entry(values: Vec, key: String) -> Result { let mut end_values = Vec::new(); let time_zero = values[0].time; + let mut prev_vmstat = values[0].clone(); for value in values { - let current_vmstat = value; + let current_vmstat = value.clone(); let current_time = current_vmstat.time; let curr_data = current_vmstat.vmstat_data.clone(); let curr_value = curr_data .get(&key) .ok_or(PDError::VisualizerVmstatValueGetError(key.to_string()))?; + let prev_data = prev_vmstat.vmstat_data.clone(); + let prev_value = prev_data + .get(&key) + .ok_or(PDError::VisualizerVmstatValueGetError(key.to_string()))?; + let mut v = *curr_value; + if !key.contains("nr_") { + v = *curr_value - *prev_value; + } let vmstat_entry = VmstatEntry { time: (current_time - time_zero), - value: *curr_value, + value: v, }; end_values.push(vmstat_entry); + prev_vmstat = value.clone(); } Ok(serde_json::to_string(&end_values)?) } @@ -95,26 +105,26 @@ fn get_entries(value: Vmstat) -> Result { } impl GetData for Vmstat { - fn process_raw_data(&mut self, buffer: Data) -> Result { + fn process_raw_data(&mut self, buffer: Data) -> Result { let raw_value = match buffer { Data::VmstatRaw(ref value) => value, _ => panic!("Invalid Data type in raw file"), }; let mut vmstat = Vmstat::new(); - let reader = BufReader::new(raw_value.data.as_bytes()); - let mut map: HashMap = HashMap::new(); - for line in reader.lines() { - let line = line?; - let mut split = line.split_whitespace(); - let name = split.next().ok_or(PDError::ProcessorOptionExtractError)?; + let reader = BufReader::new(raw_value.data.as_bytes()); + let mut map: HashMap = HashMap::new(); + for line in reader.lines() { + let line = line?; + let mut split = line.split_whitespace(); + let name = split.next().ok_or(PDError::ProcessorOptionExtractError)?; let val = split.next().ok_or(PDError::ProcessorOptionExtractError)?; - map.insert(name.to_owned(), val.parse::()?); - } + map.insert(name.to_owned(), val.parse::()?); + } vmstat.set_time(raw_value.time); vmstat.set_data(map); let processed_data = ProcessedData::Vmstat(vmstat); Ok(processed_data) - } + } fn get_data(&mut self, buffer: Vec, query: String) -> Result { let mut values = Vec::new();