From d3a68abf5619fb3e99f2858dd5592b5795139619 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sat, 25 Jul 2026 15:29:49 +0200 Subject: [PATCH] Custom ratio correlation plot --- scripts/charts/ratio_correlation_customized.r | 129 ++++++++++++++++++ scripts/menu.pl | 11 +- 2 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 scripts/charts/ratio_correlation_customized.r diff --git a/scripts/charts/ratio_correlation_customized.r b/scripts/charts/ratio_correlation_customized.r new file mode 100644 index 0000000..be7021d --- /dev/null +++ b/scripts/charts/ratio_correlation_customized.r @@ -0,0 +1,129 @@ +library(ggplot2) +library(dplyr) +library(readr) +library(stringr) +library(tidyr) + +# Usage: Rscript ratio_correlation_no_mem.r exp_abspath1 exp_abspath2 ... [resultsdata_file] +# Plots correlation between aot/c and interp/c ratios, ignoring mem benchmark +# NOTE: Just a copy of the ratio_correlation.r script where I've changed the filter in line 67 + +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") +} + +# Ignore OK_MARKER (only plot failures) and sum GROUP1_MARKER with TRAP +# Also ignore mem benchmark +all_data <- all_data |> + filter(resulttype %in% c("TRAP", "GROUP1_MARKER"), benchmark == "ip") |> + mutate(resulttype = ifelse(resulttype == "GROUP1_MARKER", "TRAP", resulttype)) + +all_data <- all_data |> + group_by(base_name, variant, benchmark, resulttype) |> + summarise(faults = sum(faults), .groups = "drop") + +baseline <- all_data |> filter(variant == "c") +comparisons <- all_data |> filter(variant != "c") + +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)") +} + +# Pivot to get aot and interp ratios side by side +ratio_wide <- ratios |> + select(base_name, benchmark, resulttype, variant, ratio) |> + pivot_wider(names_from = variant, values_from = ratio) |> + filter(!is.na(aot), !is.na(interp)) + +if (nrow(ratio_wide) == 0) { + stop("No paired aot/interp ratios found") +} + +# Compute correlation +cor_result <- cor(ratio_wide$aot, ratio_wide$interp, method = "pearson") +cat(sprintf("Pearson correlation: %.4f\n", cor_result)) + +# Create plot +plot <- ggplot( + ratio_wide, + aes(x = aot, y = interp, color = base_name, shape = resulttype) +) + + geom_point(size = 3, alpha = 0.7) + + scale_x_log10(name = "AOT / C Ratio") + + scale_y_log10(name = "Interpreter / C Ratio") + + labs( + title = sprintf("Ratio Correlation (r = %.4f)", cor_result), + color = "Experiment", + shape = "Marker" + ) + + theme_minimal() + + theme( + legend.position = "right", + plot.title = element_text(size = 14, face = "bold") + ) + +ggsave( + "injections/ratio_correlation_customized.svg", + plot = plot, + width = 10, + height = 8 +) +print("Saved ratio_correlation_customized.svg") diff --git a/scripts/menu.pl b/scripts/menu.pl index 12ffabd..565d9e5 100644 --- a/scripts/menu.pl +++ b/scripts/menu.pl @@ -575,8 +575,9 @@ my %handlers = ( # Need to know which chart uses which datafile my @faults_charts = grep { /heatmap|scatter|sankey/ } @selected_charts; my @resultsdata_charts = - grep { /result$|combined_comparison|ratio_comparison|ratio_correlation/ } - @selected_charts; + grep { + /result$|combined_comparison|ratio_comparison|ratio_correlation/ + } @selected_charts; my $faults_csv; my $resultsdata_csv; @@ -609,7 +610,8 @@ my %handlers = ( } my @combined_charts = - grep { /combined|ratio_comparison|ratio_correlation/ } @selected_charts; + grep { /combined|ratio_comparison|ratio_correlation/ } + @selected_charts; my $print_experiments = join " ", @selected_experiments; my @path_experiments = map { "$local_archive_dir/$_" } @selected_experiments; @@ -621,7 +623,8 @@ my %handlers = ( if defined $faults_csv && $chart =~ /heatmap|scatter|sankey/; push @r_args, $resultsdata_csv if defined $resultsdata_csv - && $chart =~ /result$|combined_comparison|ratio_comparison|ratio_correlation/; + && $chart =~ + /result$|combined_comparison|ratio_comparison|ratio_correlation/; system(@r_args); } },