From 2098e3fb0e8433e4bbe75bbacdcd4cd22d1467de Mon Sep 17 00:00:00 2001 From: Alwin Berger Date: Mon, 9 Sep 2024 15:23:09 +0200 Subject: [PATCH] extract worst response from trace --- state2gantt/Cargo.lock | 17 ++++---- state2gantt/Cargo.toml | 3 +- state2gantt/driver.sh | 2 +- state2gantt/src/main.rs | 87 ++++++++++++++++++++++++++++++++++++----- 4 files changed, 89 insertions(+), 20 deletions(-) diff --git a/state2gantt/Cargo.lock b/state2gantt/Cargo.lock index 8984255..4803461 100644 --- a/state2gantt/Cargo.lock +++ b/state2gantt/Cargo.lock @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" @@ -305,9 +305,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.7" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" dependencies = [ "clap_builder", "clap_derive", @@ -315,9 +315,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.7" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" dependencies = [ "anstream", "anstyle", @@ -327,9 +327,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.5" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ "heck", "proc-macro2", @@ -1580,6 +1580,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" name = "state2gantt" version = "0.1.0" dependencies = [ + "clap", "fret", "rand", "ron", diff --git a/state2gantt/Cargo.toml b/state2gantt/Cargo.toml index f0d62a7..aa50c44 100644 --- a/state2gantt/Cargo.toml +++ b/state2gantt/Cargo.toml @@ -11,4 +11,5 @@ serde = { version = "1.0", default-features = false, features = ["alloc"] } # se # hashbrown = { version = "0.12", features = ["serde", "ahash-compile-time-rng"] } # A faster hashmap, nostd compatible # petgraph = { version="0.6.0", features = ["serde-1"] } ron = "0.7" # write serialized data - including hashmaps -rand = "0.5" \ No newline at end of file +rand = "0.5" +clap = "4.5.17" diff --git a/state2gantt/driver.sh b/state2gantt/driver.sh index 6924e22..2c4d375 100755 --- a/state2gantt/driver.sh +++ b/state2gantt/driver.sh @@ -2,6 +2,6 @@ if [ -z "$1" ]; then exit 1; fi OFILE_A="$(dirname "$1")/$(basename -s .trace.ron "$1")_a.csv" OFILE_B="$(dirname "$1")/$(basename -s .trace.ron "$1")_b.csv" -~/code/FRET/state2gantt/target/debug/state2gantt $1 "$OFILE_A" "$OFILE_B" +~/code/FRET/state2gantt/target/debug/state2gantt -i $1 -a "$OFILE_A" -r "$OFILE_B" # ~/code/FRET/state2gantt/plot.r "$OFILE_A" html ~/code/FRET/state2gantt/plot_response.r "$OFILE_A" "$OFILE_B" html \ No newline at end of file diff --git a/state2gantt/src/main.rs b/state2gantt/src/main.rs index ca98f94..bcc9420 100644 --- a/state2gantt/src/main.rs +++ b/state2gantt/src/main.rs @@ -1,20 +1,87 @@ use std::collections::HashMap; use std::path::PathBuf; use std::{env,fs}; -use fret::systemstate::RefinedFreeRTOSSystemState; +use fret::systemstate::{ExecInterval, ReducedFreeRTOSSystemState}; +use std::io::Write; +use clap::Parser; + +#[derive(Parser)] +struct Config { + /// Input Trace + #[arg(short, long, value_name = "FILE")] + input_trace: PathBuf, + + /// Output for activations + #[arg(short, long, value_name = "FILE")] + activation: Option, + + /// Output for Release-Response intervals + #[arg(short, long, value_name = "FILE")] + response: Option, + + /// Focussed Task + #[arg(short, long, value_name = "TASK")] + task: Option, +} fn main() { - let args : Vec = env::args().collect(); + // let args : Vec = env::args().collect(); + let conf = Config::parse(); - let path_a = PathBuf::from(args[1].clone()); - let raw_a = fs::read(path_a).expect("Can not read dumped traces b"); - // let path_b = PathBuf::from(args[2].clone()); + let input_path = conf.input_trace; + let raw_input = fs::read(input_path).expect("Can not read dumped traces"); - let trace : Vec = ron::from_str(&String::from_utf8_lossy(&raw_a)).expect("Can not parse HashMap"); + let activation_path = conf.activation; + let instance_path = conf.response; - println!("start,end,name"); - for s in trace { - if s.current_task.task_name == "Tmr Svc" {continue;} - println!("{},{},{}",s.start_tick,s.end_tick,s.current_task.task_name); + let mut activation_file = activation_path.map(|x| std::fs::OpenOptions::new() + .read(false) + .write(true) + .create(true) + .append(false) + .open(x).expect("Could not create file")); + + let mut level_per_task : HashMap<&String, u32> = HashMap::new(); + + + let trace : (Vec, HashMap, Vec<(u64, u64, String)>) = ron::from_str(&String::from_utf8_lossy(&raw_input)).expect("Can not parse HashMap"); + for s in &trace.0 { + if s.level == 0 { + level_per_task.insert(&trace.1[&s.start_state].current_task.task_name,trace.1[&s.start_state].current_task.priority); + } + } + + let limits = conf.task.as_ref().map(|task| trace.2.iter().filter_map(move |x| if &x.2 == task {Some(x)} else {None}).max_by_key(|x| x.1-x.0)).flatten().map(|x| x.0..x.1); + if let Some(limits) = &limits { + println!("Limits: {} - {}",limits.start,limits.end); + } + + activation_file.as_mut().map(|x| writeln!(x,"start,end,prio,name").expect("Could not write to file")); + for s in trace.0 { + if limits.as_ref().map(|x| !x.contains(&s.start_tick) && !x.contains(&s.end_tick) ).unwrap_or(false) { + continue; + } + if s.level == 0 { + activation_file.as_mut().map(|x| writeln!(x,"{},{},{},{}",s.start_tick,s.end_tick,trace.1[&s.start_state].current_task.priority,trace.1[&s.start_state].current_task.task_name).expect("Could not write to file")); + } else { + activation_file.as_mut().map(|x| writeln!(x,"{},{},-{},{}",s.start_tick,s.end_tick,s.level,s.start_capture.1).expect("Could not write to file")); + } + } + + let instance_file = instance_path.map(|x| std::fs::OpenOptions::new() + .read(false) + .write(true) + .create(true) + .append(false) + .open(x).expect("Could not create file")); + + if let Some(mut file) = instance_file { + writeln!(file,"start,end,prio,name").expect("Could not write to file"); + for s in trace.2 { + if limits.as_ref().map(|x| !x.contains(&s.0) && !x.contains(&s.1) ).unwrap_or(false) { + continue; + } + writeln!(file,"{},{},{},{}",s.0,s.1,level_per_task[&s.2],s.2).expect("Could not write to file"); + } } }