Replace the composition chart with a probability chart that actually sums to 100%
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
library(readr)
|
||||
library(stringr)
|
||||
library(tidyr)
|
||||
|
||||
# Usage: Rscript combined_fault_probability.r exp_abspath1 ... 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)
|
||||
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)
|
||||
}
|
||||
|
||||
# Load data
|
||||
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)
|
||||
}
|
||||
|
||||
# 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)
|
||||
filename <- paste0("injections/fault_probability", out_suffix, ".svg")
|
||||
ggsave(filename, plot = plot, width = 13, height = 8)
|
||||
Reference in New Issue
Block a user