Skip to content

Commit

Permalink
Add GraphLimits for MeminfoData
Browse files Browse the repository at this point in the history
  • Loading branch information
janaknat committed Sep 15, 2023
1 parent efdf5f2 commit 40a5d7c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 17 deletions.
24 changes: 17 additions & 7 deletions src/data/meminfodata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<MeminfoData>, key: String) -> Result<String> {
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)]
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
53 changes: 43 additions & 10 deletions src/html_files/meminfo.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
let got_meminfo_data = false;
let TB = 1073741824;
let GB = 1048576;
function get_divisor_unit(values) {

let meminfo_average: Map<string, number> = new Map<string, number>();
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,
Expand All @@ -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")) {
Expand All @@ -62,13 +91,15 @@ function getMeminfo(elem, key, run_data) {
type: 'scatter',
};
var TESTER = elem;
let limits = key_limits.get(key);
var layout = {
title: key,
xaxis: {
title: 'Time (s)',
},
yaxis: {
title: `${unit}`,
range: [limits.low/divisor, limits.high/divisor],
}
};
Plotly.newPlot(TESTER, [meminfodata], layout, { frameMargins: 0 });
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 40a5d7c

Please sign in to comment.