Skip to content

Commit

Permalink
Visualizer updates
Browse files Browse the repository at this point in the history
Updates:
* CPU Utilization graph y-axis is always 100%.
* Diskstat read, sector graph updates.
* VMStat graph updates.
  • Loading branch information
janaknat committed Mar 14, 2023
1 parent 6e9b84a commit 1b9e5ab
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/bin/html_files/cpu_utilization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
3 changes: 0 additions & 3 deletions src/bin/html_files/perf_stat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,18 @@ 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;
cpu_stat.x_time = [];
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);
Expand Down
2 changes: 2 additions & 0 deletions src/data/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
23 changes: 12 additions & 11 deletions src/data/diskstats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,22 @@ fn get_disk_names(value: Diskstats) -> Vec<String> {
fn get_values(values: Vec<Diskstats>, key: String, unit: String) -> Result<String> {
let mut ev: BTreeMap<String, DiskValues> = 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();
Expand All @@ -240,7 +245,7 @@ fn get_values(values: Vec<Diskstats>, key: String, unit: String) -> Result<Strin
if key == "In Progress" {
stat_value = *disk.stat.get(&key.clone()).unwrap() as f64;
} else {
stat_value = (*disk.stat.get(&key.clone()).unwrap() as i64 - *prev_value.get(&disk.name).unwrap() as i64) as f64/ factor as f64;
stat_value = (*disk.stat.get(&key.clone()).unwrap() as i64 - *prev_value.get(&disk.name).unwrap() as i64) as f64 * mult_factor as f64 / factor as f64;
}
let dv = DiskValue {
time: (v.time - time_zero),
Expand All @@ -266,13 +271,9 @@ fn get_keys(user_unit: String) -> Result<String> {
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});
}
Expand Down
34 changes: 22 additions & 12 deletions src/data/vmstat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,30 @@ struct VmstatEntry {
fn get_entry(values: Vec<Vmstat>, key: String) -> Result<String> {
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)?)
}
Expand All @@ -95,26 +105,26 @@ fn get_entries(value: Vmstat) -> Result<String> {
}

impl GetData for Vmstat {
fn process_raw_data(&mut self, buffer: Data) -> Result<ProcessedData> {
fn process_raw_data(&mut self, buffer: Data) -> Result<ProcessedData> {
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<String, i64> = 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<String, i64> = 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::<i64>()?);
}
map.insert(name.to_owned(), val.parse::<i64>()?);
}
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<ProcessedData>, query: String) -> Result<String> {
let mut values = Vec::new();
Expand Down

0 comments on commit 1b9e5ab

Please sign in to comment.