diff --git a/state2gantt/plot_response.r b/state2gantt/plot_response.r index 988cd80..9f272ea 100755 --- a/state2gantt/plot_response.r +++ b/state2gantt/plot_response.r @@ -9,12 +9,25 @@ QEMU_SHIFT<-5 TIMESCALE<-1000000 # Function to create a Gantt chart with dots on short segments -create_gantt_chart <- function(csv_file_a, csv_file_b, MIN_WIDTH, output_format = NULL) { +create_gantt_chart <- function(csv_file_a, csv_file_b, MIN_WIDTH, output_format = NULL, startpoint, endpoint) { # Read the CSV file df <- read_csv(csv_file_a) # df_b <- read_csv(csv_file_b) df_b <- read_csv(csv_file_b, col_types = cols(.default = "d", name = col_character())) # df <- df %>% bind_rows(df_b) + + # Cut out everything outside the range + df <- df %>% + filter(end >= startpoint & start <= endpoint) %>% rowwise %>% mutate(end = min(end, endpoint), start = max(start, startpoint)) + + df_b <- df_b %>% + filter(end >= startpoint & start <= endpoint) %>% rowwise %>% mutate(end = min(end, endpoint), start = max(start, startpoint)) + + # Add a placeholder for all tasks that don't have job instances in the range + s <- min(df$start) + placeholder <- df_b %>% mutate(start = s, end = s) + df <- df %>% bind_rows(placeholder) + # Ensure start and end columns are treated as integers df <- df %>% @@ -47,7 +60,7 @@ create_gantt_chart <- function(csv_file_a, csv_file_b, MIN_WIDTH, output_format color = "blue", size = 2) # Add dots on segments shorter than MIN_WIDTH - p <- p + geom_point(data = df %>% filter(width < MIN_WIDTH), + p <- p + geom_point(data = df %>% filter(width < MIN_WIDTH & width > 0), aes(x = start, y = name), color = "red", size = 1) @@ -73,17 +86,24 @@ create_gantt_chart <- function(csv_file_a, csv_file_b, MIN_WIDTH, output_format # Main execution args <- commandArgs(trailingOnly = TRUE) -if (length(args) < 2 || length(args) > 3) { - stop("Usage: Rscript script.R [output_format]") +if (length(args) < 2 || length(args) > 5) { + stop("Usage: Rscript script.R [output_format] [ ]") } else { csv_file_a <- args[1] csv_file_b <- args[2] - if (length(args) == 3) { + if (length(args) >= 3) { output_format <- args[3] } else { output_format <- NULL } + if (length(args) >= 5) { + start <- as.integer(args[4]) + end <- as.integer(args[5]) + } else { + start <- 0 + end <- Inf + } } MIN_WIDTH <- 500 # You can set your desired minimum width here -create_gantt_chart(csv_file_a, csv_file_b, MIN_WIDTH, output_format) +create_gantt_chart(csv_file_a, csv_file_b, MIN_WIDTH, output_format, start, end) diff --git a/state2gantt/src/main.rs b/state2gantt/src/main.rs index bcc9420..8be131e 100644 --- a/state2gantt/src/main.rs +++ b/state2gantt/src/main.rs @@ -44,7 +44,7 @@ fn main() { 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"); + let mut 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); @@ -57,9 +57,13 @@ fn main() { } 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; + for s in trace.0.iter_mut() { + if let Some(l) = &limits { + if s.start_tick > l.end || s.end_tick < l.start { + continue; + } + s.start_tick = s.start_tick.max(l.start); + s.end_tick = s.end_tick.min(l.end); } 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")); @@ -77,10 +81,17 @@ fn main() { if let Some(mut file) = instance_file { writeln!(file,"start,end,prio,name").expect("Could not write to file"); - for s in trace.2 { + for s in trace.2.iter_mut() { if limits.as_ref().map(|x| !x.contains(&s.0) && !x.contains(&s.1) ).unwrap_or(false) { continue; } + if let Some(l) = &limits { + if s.0 > l.end || s.1 < l.start { + continue; + } + s.0 = s.0.max(l.start); + s.1 = s.1.min(l.end); + } writeln!(file,"{},{},{},{}",s.0,s.1,level_per_task[&s.2],s.2).expect("Could not write to file"); } }