137 lines
3.5 KiB
R
137 lines
3.5 KiB
R
library(ggplot2)
|
|
library(dplyr)
|
|
library(readr)
|
|
library(stringr)
|
|
library(tidyr)
|
|
|
|
# Usage: Rscript combined_fault_probability.r exp1 exp2 ... queries_dir charts_dir [resultsdata_file]
|
|
#
|
|
# Divides by the faultspace area instead of by a marker total, which makes the
|
|
# running modes comparable: raw counts scale with how long WAMR runs, so they
|
|
# say more about execution length than about susceptibility.
|
|
#
|
|
# Each segment is P[outcome] for a uniformly random single-bit flip in the
|
|
# traced fault space, so a bar's height is P[anything goes wrong].
|
|
#
|
|
# Replaces combined_fault_composition.r, which divided by the marker total and
|
|
# was therefore this chart with every bar rescaled to 100%.
|
|
|
|
args <- commandArgs(trailingOnly = TRUE)
|
|
|
|
csv_suffix <- if (grepl("\\.csv$", args[length(args)])) {
|
|
args[length(args)]
|
|
} else {
|
|
"resultsdata.csv"
|
|
}
|
|
tail_args <- if (grepl("\\.csv$", args[length(args)])) {
|
|
args[-length(args)]
|
|
} else {
|
|
args
|
|
}
|
|
|
|
if (length(tail_args) < 4) {
|
|
stop(paste(
|
|
"Usage: combined_fault_probability.r",
|
|
"<exp1> <exp2> ... <queries_dir> <charts_dir> [resultsdata_file]"
|
|
))
|
|
}
|
|
|
|
charts_dir <- tail_args[length(tail_args)]
|
|
queries_dir <- tail_args[length(tail_args) - 1]
|
|
exp_args <- tail_args[-c(length(tail_args) - 1, length(tail_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)
|
|
}
|
|
|
|
# "tacle-kernel-bsort" -> "bsort", otherwise it doesn't fit
|
|
base_name <- sub("^tacle-[^-]+-", "", match[1, 2])
|
|
|
|
list(base_name = base_name, variant = match[1, 3], path = path)
|
|
}
|
|
|
|
# Load data
|
|
all_data <- data.frame()
|
|
|
|
for (arg in exp_args) {
|
|
info <- extract_info(arg)
|
|
if (is.null(info)) {
|
|
next
|
|
}
|
|
|
|
csv_file <- file.path(queries_dir, paste0(arg, "_", 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)
|
|
}
|
|
|
|
# TODO: Finally put all the bullshit before this in some shared space
|
|
|
|
if (nrow(all_data) == 0) {
|
|
stop("No data loaded")
|
|
}
|
|
|
|
marker_order <- c(
|
|
"OK_MARKER",
|
|
"DETECTED_MARKER",
|
|
"GROUP1_MARKER",
|
|
"TRAP",
|
|
"TIMEOUT",
|
|
"WRITE_TEXTSEGMENT",
|
|
"ACCESS_OUTERSPACE",
|
|
"FAIL_MARKER"
|
|
)
|
|
|
|
# Don't merge GROUP1_MARKER into TRAP for this chart
|
|
# Also keep the OK_MARKERs, so the "sum to 100%" is accurate
|
|
probability <- all_data |>
|
|
group_by(base_name, variant, benchmark) |>
|
|
mutate(frac = faults / sum(faults, na.rm = TRUE)) |>
|
|
ungroup()
|
|
|
|
# Don't print alphabetically
|
|
probability$resulttype <- factor(probability$resulttype, levels = marker_order)
|
|
probability$variant <- factor(
|
|
probability$variant,
|
|
levels = c("c", "aot", "interp")
|
|
)
|
|
|
|
plot <- ggplot(
|
|
probability,
|
|
aes(x = variant, y = frac, fill = resulttype)
|
|
) +
|
|
geom_col() +
|
|
facet_grid(benchmark ~ base_name) +
|
|
scale_y_continuous(labels = scales::percent) +
|
|
labs(
|
|
title = "Fault Probability per Fault Space",
|
|
x = NULL,
|
|
y = "Probability of Failure",
|
|
fill = "Fault Type"
|
|
) +
|
|
theme_minimal() +
|
|
theme(
|
|
plot.title = element_text(size = 13, face = "bold"),
|
|
axis.text.x = element_text(angle = 45, hjust = 1)
|
|
)
|
|
|
|
out_suffix <- gsub("^resultsdata|\\.csv$", "", csv_suffix)
|
|
dir.create(charts_dir, showWarnings = FALSE, recursive = TRUE)
|
|
filename <- file.path(
|
|
charts_dir,
|
|
paste0("fault_probability", out_suffix, ".svg")
|
|
)
|
|
ggsave(filename, plot = plot, width = 13, height = 8)
|