105 lines
2.5 KiB
R
105 lines
2.5 KiB
R
library(ggplot2)
|
|
library(dplyr)
|
|
library(readr)
|
|
library(stringr)
|
|
|
|
# Usage: Rscript ratio_comparison.r exp_abspath1 exp_abspath2 ... [resultsdata_file]
|
|
# Plots every benchmark separately
|
|
|
|
args <- commandArgs(trailingOnly = TRUE)
|
|
if (length(args) < 2) {
|
|
stop("Need at least 2 experiments")
|
|
}
|
|
|
|
csv_suffix <- if (grepl("\\.csv$", args[length(args)])) {
|
|
args[length(args)]
|
|
} else {
|
|
"resultsdata.csv"
|
|
}
|
|
exp_args <- if (grepl("\\.csv$", args[length(args)])) {
|
|
args[-length(args)]
|
|
} else {
|
|
args
|
|
}
|
|
|
|
extract_info <- function(path) {
|
|
dir_name <- basename(path)
|
|
match <- str_match(
|
|
dir_name,
|
|
"^\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}_(.+?)_(c|aot|interp)_"
|
|
)
|
|
if (is.na(match[1, 1])) {
|
|
warning(paste("Could not parse:", dir_name))
|
|
return(NULL)
|
|
}
|
|
list(base_name = match[1, 2], variant = match[1, 3], path = path)
|
|
}
|
|
|
|
all_data <- data.frame()
|
|
|
|
for (arg in exp_args) {
|
|
info <- extract_info(arg)
|
|
if (is.null(info)) {
|
|
next
|
|
}
|
|
|
|
csv_file <- file.path(info$path, csv_suffix)
|
|
if (!file.exists(csv_file)) {
|
|
warning(paste("Missing:", csv_file))
|
|
next
|
|
}
|
|
|
|
df <- read_csv(csv_file, col_types = cols())
|
|
df$base_name <- info$base_name
|
|
df$variant <- info$variant
|
|
all_data <- bind_rows(all_data, df)
|
|
}
|
|
|
|
if (nrow(all_data) == 0) {
|
|
stop("No data loaded")
|
|
}
|
|
|
|
baseline <- all_data |> filter(variant == "c")
|
|
comparisons <- all_data |> filter(variant != "c")
|
|
|
|
# Join comparisons with baseline (differentiate by _baseline suffix)
|
|
# and add ratio column
|
|
ratios <- comparisons |>
|
|
left_join(
|
|
baseline |> select(base_name, benchmark, resulttype, faults),
|
|
by = c("base_name", "benchmark", "resulttype"),
|
|
suffix = c("", "_baseline")
|
|
) |>
|
|
filter(!is.na(faults_baseline), faults_baseline > 0) |>
|
|
mutate(ratio = faults / faults_baseline)
|
|
|
|
if (nrow(ratios) == 0) {
|
|
stop("No ratios computed (missing baseline or zero values)")
|
|
}
|
|
|
|
ratios$label <- paste0(ratios$benchmark, ".", ratios$resulttype)
|
|
|
|
plot <- ggplot(
|
|
ratios,
|
|
aes(x = label, y = ratio, color = variant, group = variant)
|
|
) +
|
|
geom_point(size = 2) +
|
|
geom_line() +
|
|
facet_wrap(~base_name) +
|
|
scale_y_log10(name = "Ratio (to C)") +
|
|
scale_x_discrete(name = "Fault Type") +
|
|
labs(
|
|
title = "Fault Count Ratios",
|
|
color = "Variant"
|
|
) +
|
|
theme_minimal() +
|
|
theme(
|
|
axis.text.x = element_text(angle = 90, hjust = 1),
|
|
plot.title = element_text(size = 14, face = "bold")
|
|
)
|
|
|
|
suffix <- gsub("^resultsdata|\\.csv$", "", csv_suffix)
|
|
outfile <- paste0("injections/ratio_comparison", suffix, ".svg")
|
|
ggsave(outfile, plot = plot, width = 12, height = 8)
|
|
print(paste("Saved", outfile))
|