From 40a5d7cf3e96854259dd0df89e565c8176977565 Mon Sep 17 00:00:00 2001 From: Janakarajan Natarajan Date: Fri, 15 Sep 2023 20:46:57 +0000 Subject: [PATCH] Add GraphLimits for MeminfoData --- src/data/meminfodata.rs | 24 ++++++++++++------ src/html_files/meminfo.ts | 53 +++++++++++++++++++++++++++++++-------- 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/src/data/meminfodata.rs b/src/data/meminfodata.rs index 85ee5052..df78931a 100644 --- a/src/data/meminfodata.rs +++ b/src/data/meminfodata.rs @@ -3,7 +3,7 @@ extern crate ctor; use anyhow::Result; use crate::data::{CollectData, Data, ProcessedData, DataType, TimeEnum}; use crate::{PDError, PERFORMANCE_DATA, VISUALIZATION_DATA}; -use crate::visualizer::{DataVisualizer, GetData}; +use crate::visualizer::{DataVisualizer, GetData, GraphMetadata, GraphLimitType}; use chrono::prelude::*; use ctor::ctor; use log::{trace}; @@ -163,17 +163,27 @@ pub struct MemEntry { pub value: u64, } +#[derive(Serialize, Deserialize, Debug, Clone)] +struct EndMemValues { + pub data: MemData, + pub metadata: GraphMetadata, +} + fn get_values(values: Vec, key: String) -> Result { let time_zero = values[0].time; + let mut metadata = GraphMetadata::new(); let mut end_value = MemData {name: key.clone(), values: Vec::new()}; for v in values { let value = v.data .get(&key) .ok_or(PDError::VisualizerMeminfoValueGetError(key.to_string()))?; - let mementry = MemEntry {time: v.time - time_zero, value: *value}; + /* Bytes => kB */ + let mementry = MemEntry {time: v.time - time_zero, value: *value / 1024}; + metadata.update_limits(GraphLimitType::UInt64(mementry.value)); end_value.values.push(mementry); } - return Ok(serde_json::to_string(&end_value)?) + let end_values = EndMemValues {data: end_value, metadata: metadata}; + return Ok(serde_json::to_string(&end_values)?) } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -332,7 +342,7 @@ fn init_meminfo() { #[cfg(test)] mod tests { - use super::{MeminfoDataRaw, MeminfoData, MeminfoKeys, MemData}; + use super::{MeminfoDataRaw, MeminfoData, MeminfoKeys, EndMemValues}; use crate::data::{CollectData, Data, ProcessedData}; use crate::visualizer::GetData; use std::collections::HashMap; @@ -400,8 +410,8 @@ mod tests { processed_buffer.push(MeminfoData::new().process_raw_data(buf).unwrap()); } let json = MeminfoData::new().get_data(processed_buffer, "run=test&get=values&key=Mem Total".to_string()).unwrap(); - let memdata: MemData = serde_json::from_str(&json).unwrap(); - assert!(memdata.name == "Mem Total"); - assert!(memdata.values.len() > 0); + let memdata: EndMemValues = serde_json::from_str(&json).unwrap(); + assert!(memdata.data.name == "Mem Total"); + assert!(memdata.data.values.len() > 0); } } diff --git a/src/html_files/meminfo.ts b/src/html_files/meminfo.ts index 9e794c0f..51d38916 100644 --- a/src/html_files/meminfo.ts +++ b/src/html_files/meminfo.ts @@ -1,12 +1,43 @@ let got_meminfo_data = false; let TB = 1073741824; let GB = 1048576; -function get_divisor_unit(values) { + +let meminfo_average: Map = new Map(); +function form_meminfo_averages() { + runs_raw.forEach(function (value, index, arr) { + let this_run_data; + for (let i = 0; i < meminfo_raw_data['runs'].length; i++) { + if (meminfo_raw_data['runs'][i]['name'] == value) { + this_run_data = meminfo_raw_data['runs'][i]; + let keys = this_run_data['keys']; + let values = this_run_data['key_values']; + keys.forEach(function (v, i, a) { + var run_data = JSON.parse(values[v]); + let y_data = []; + run_data.data.values.forEach(function (rv, ri, ra) { + y_data.push(rv.value); + }) + var total = 0; + for (i = 0; i < y_data.length; i++) { + total += y_data[i]; + } + let average = total / y_data.length; + if (meminfo_average.has(v)) { + if (average > meminfo_average.get(v)) { + meminfo_average.set(v, average); + } + } else { + meminfo_average.set(v, average); + } + }); + } + } + }); +} + +function get_divisor_unit(key) { var total = 0; - for (i = 0; i < values.length; i++) { - total += values[i]; - } - let average = total / values.length; + let average = meminfo_average.get(key); if (average > TB) { return { divisor: TB, @@ -29,14 +60,12 @@ function getMeminfo(elem, key, run_data) { var data = JSON.parse(run_data); var x_data = []; var y_data = []; - data.values.forEach(function (value, index, arr) { + data.data.values.forEach(function (value, index, arr) { x_data.push(value.time.TimeDiff); - - /* Bytes => kB */ - y_data.push(value.value / 1024); + y_data.push(value.value); }) - var { divisor, unit } = get_divisor_unit(y_data); + var { divisor, unit } = get_divisor_unit(key); if (key.includes("Mem Total") || key.includes("Vmalloc Total") || key.includes("Hugepagesize")) { @@ -62,6 +91,7 @@ function getMeminfo(elem, key, run_data) { type: 'scatter', }; var TESTER = elem; + let limits = key_limits.get(key); var layout = { title: key, xaxis: { @@ -69,6 +99,7 @@ function getMeminfo(elem, key, run_data) { }, yaxis: { title: `${unit}`, + range: [limits.low/divisor, limits.high/divisor], } }; Plotly.newPlot(TESTER, [meminfodata], layout, { frameMargins: 0 }); @@ -98,6 +129,8 @@ function meminfo() { } var run_width = 100 / data.length; clearElements('meminfo-runs'); + form_meminfo_averages(); + form_graph_limits(meminfo_raw_data); data.forEach(function (value, index, arr) { // Run div var run_div = document.createElement('div');