fix plotting in range
This commit is contained in:
parent
2098e3fb0e
commit
a2291174f8
@ -9,12 +9,25 @@ QEMU_SHIFT<-5
|
|||||||
TIMESCALE<-1000000
|
TIMESCALE<-1000000
|
||||||
|
|
||||||
# Function to create a Gantt chart with dots on short segments
|
# 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
|
# Read the CSV file
|
||||||
df <- read_csv(csv_file_a)
|
df <- read_csv(csv_file_a)
|
||||||
# df_b <- read_csv(csv_file_b)
|
# df_b <- read_csv(csv_file_b)
|
||||||
df_b <- read_csv(csv_file_b, col_types = cols(.default = "d", name = col_character()))
|
df_b <- read_csv(csv_file_b, col_types = cols(.default = "d", name = col_character()))
|
||||||
# df <- df %>% bind_rows(df_b)
|
# 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
|
# Ensure start and end columns are treated as integers
|
||||||
df <- df %>%
|
df <- df %>%
|
||||||
@ -47,7 +60,7 @@ create_gantt_chart <- function(csv_file_a, csv_file_b, MIN_WIDTH, output_format
|
|||||||
color = "blue", size = 2)
|
color = "blue", size = 2)
|
||||||
|
|
||||||
# Add dots on segments shorter than MIN_WIDTH
|
# 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),
|
aes(x = start, y = name),
|
||||||
color = "red", size = 1)
|
color = "red", size = 1)
|
||||||
|
|
||||||
@ -73,17 +86,24 @@ create_gantt_chart <- function(csv_file_a, csv_file_b, MIN_WIDTH, output_format
|
|||||||
|
|
||||||
# Main execution
|
# Main execution
|
||||||
args <- commandArgs(trailingOnly = TRUE)
|
args <- commandArgs(trailingOnly = TRUE)
|
||||||
if (length(args) < 2 || length(args) > 3) {
|
if (length(args) < 2 || length(args) > 5) {
|
||||||
stop("Usage: Rscript script.R <csv_file> <csv_file> [output_format]")
|
stop("Usage: Rscript script.R <csv_file> <csv_file> [output_format] [<strt> <end>]")
|
||||||
} else {
|
} else {
|
||||||
csv_file_a <- args[1]
|
csv_file_a <- args[1]
|
||||||
csv_file_b <- args[2]
|
csv_file_b <- args[2]
|
||||||
if (length(args) == 3) {
|
if (length(args) >= 3) {
|
||||||
output_format <- args[3]
|
output_format <- args[3]
|
||||||
} else {
|
} else {
|
||||||
output_format <- NULL
|
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
|
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)
|
||||||
|
@ -44,7 +44,7 @@ fn main() {
|
|||||||
let mut level_per_task : HashMap<&String, u32> = HashMap::new();
|
let mut level_per_task : HashMap<&String, u32> = HashMap::new();
|
||||||
|
|
||||||
|
|
||||||
let trace : (Vec<ExecInterval>, HashMap<u64, ReducedFreeRTOSSystemState>, Vec<(u64, u64, String)>) = ron::from_str(&String::from_utf8_lossy(&raw_input)).expect("Can not parse HashMap");
|
let mut trace : (Vec<ExecInterval>, HashMap<u64, ReducedFreeRTOSSystemState>, Vec<(u64, u64, String)>) = ron::from_str(&String::from_utf8_lossy(&raw_input)).expect("Can not parse HashMap");
|
||||||
for s in &trace.0 {
|
for s in &trace.0 {
|
||||||
if s.level == 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);
|
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"));
|
activation_file.as_mut().map(|x| writeln!(x,"start,end,prio,name").expect("Could not write to file"));
|
||||||
for s in trace.0 {
|
for s in trace.0.iter_mut() {
|
||||||
if limits.as_ref().map(|x| !x.contains(&s.start_tick) && !x.contains(&s.end_tick) ).unwrap_or(false) {
|
if let Some(l) = &limits {
|
||||||
continue;
|
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 {
|
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"));
|
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 {
|
if let Some(mut file) = instance_file {
|
||||||
writeln!(file,"start,end,prio,name").expect("Could not write to 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) {
|
if limits.as_ref().map(|x| !x.contains(&s.0) && !x.contains(&s.1) ).unwrap_or(false) {
|
||||||
continue;
|
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");
|
writeln!(file,"{},{},{},{}",s.0,s.1,level_per_task[&s.2],s.2).expect("Could not write to file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user