rework plotting

This commit is contained in:
Alwin Berger 2023-02-28 17:01:04 +01:00
parent e0f73778e2
commit 9336b932d0

View File

@ -1,38 +1,29 @@
library("mosaic")
library("dplyr")
args = commandArgs(trailingOnly=TRUE)
#myolors=c("#339933","#0066ff","#993300") # grün, balu, rot
myolors=c("green","blue","red", "yellow", "pink", "black") # grün, balu, rot
if (length(args)==0) {
runtype="timedump"
runtype="mnt/timedump"
target="waters"
filename_1=sprintf("%s.png",target)
filename_2=sprintf("%s_maxline.png",target)
filename_3=sprintf("%s_hist.png",target)
outputpath="~/code/FRET/LibAFL/fuzzers/FRET/benchmark/"
#MY_SELECTION <- c('state', 'afl', 'graph', 'random')
SAVE_FILE=TRUE
} else {
runtype=args[1]
target=args[2]
filename_1=sprintf("%s.png",args[2])
filename_2=sprintf("%s_maxline.png",args[2])
filename_3=sprintf("%s_hist.png",args[2])
# filename_1=args[3]
outputpath=args[3]
MY_SELECTION <- args[4:length(args)]
SAVE_FILE=TRUE
}
library("dplyr")
COLORS <- c("dark grey","blue", "red", "green", "magenta", "orange", "cyan", "pink", "black", "orange")
#MY_COLORS=c("green","blue","red", "orange", "pink", "black")
MY_COLORS <- c("green", "blue", "red", "magenta", "orange", "cyan", "pink", "black", "orange", "black")
BENCHDIR=sprintf("~/code/FRET/LibAFL/fuzzers/FRET/benchmark/%s",runtype)
BASENAMES=Filter(function(x) x!="",list.dirs(BENCHDIR,full.names=FALSE))
PATTERNS=c(".*.0",
".*.1",
".*.2",
".*.3",
".*.4",
".*.5",
".*.6",
".*.7",
".*.8",
".*.9")
PATTERNS="%s.[0-9]*$"
#RIBBON='sd'
#RIBBON='span'
RIBBON='both'
# Trimm a list of data frames to common length
trim_data <- function(input,len=NULL) {
@ -42,12 +33,10 @@ trim_data <- function(input,len=NULL) {
return(lapply(input, function(d) slice_head(d,n=len)))
}
length_of_data <- function(input) {
min(sapply(input, function(v) dim(v)[1]))
}
# Takes a flat list
trace2maxline <- function(tr) {
maxline = tr
@ -75,91 +64,92 @@ frame2maxlines <- function(tr) {
return(tr)
}
maxlines2plot <- function(maxlines) {
min_length <- min(sapply(maxlines, function(v) dim(v)[1]))
ml_cut <- lapply(maxlines, function(v) v[1:min_length,])
plot(seq_len(min_length),unlist(ml_cut[[1]]),"l",xlab="Index",ylab="WOET",col=COLORS[1],ylim=c(best, worst))
for (ml in seq_len(length(maxlines))[2:length(maxlines)]) {
lines(seq_len(min_length),unlist(ml_cut[ml]),"l",col=COLORS[ml])
}
lines(seq_len(min_length),rep_len(best, min_length),col="black")
lines(seq_len(min_length),rep_len(best_success, min_length),col="black")
lines(seq_len(min_length),rep_len(worst_trace, min_length),col="green")
lines(seq_len(min_length),rep_len(worst, min_length),col="black")
legend("bottomright",legend=lapply(maxlines,names),col = COLORS[1:length(maxlines)], lwd=2)
}
frame2plot <- function(maxlines,colors=NULL,draw_extreme=TRUE,doint=FALSE,over_name=NULL) {
if (is.null(colors)) {
colors <- COLORS
}
min_length <- dim(maxlines)[1]
cur_worst <- worst
if (doint) {
cur_worst <- worst_int
}
plot(seq_len(min_length),unlist(maxlines[[1]]),"l",xlab="Execution",ylab="Worst observed response time",col=colors[1],ylim=c(min(best,min(maxlines)), max(cur_worst,max(maxlines))))
for (ml in seq_len(length(maxlines))[2:length(maxlines)]) {
lines(seq_len(min_length),unlist(maxlines[ml]),"l",col=colors[ml])
}
if (draw_extreme) {
if (!doint) {
nam <- c(names(maxlines),"worst case") #,"best case"
col <- c(colors[1:length(maxlines)],"black") #,"black"
ltp <- c(rep_len("solid",length(maxlines)),"longdash") # ,"longdash"
lines(seq_len(min_length),rep_len(worst, min_length),col=col[length(maxlines)+1],lty=ltp[length(maxlines)+1])
#nam <- c(names(maxlines),"worst trace","worst case") #,"best case"
#col <- c(colors[1:length(maxlines)],"black","black") #,"black"
#ltp <- c(rep_len("solid",length(maxlines)),"dotted","longdash") # ,"longdash"
#lines(seq_len(min_length),rep_len(best, min_length),col=col[length(maxlines)+1],lty=ltp[length(maxlines)+1])
#lines(seq_len(min_length),rep_len(best_success, min_length),col="black")
#lines(seq_len(min_length),rep_len(worst_trace, min_length),col=col[length(maxlines)+1],lty=ltp[length(maxlines)+1])
#lines(seq_len(min_length),rep_len(worst, min_length),col=col[length(maxlines)+2],lty=ltp[length(maxlines)+2])
} else {
nam <- c(names(maxlines),"worst case")
col <- c(colors[1:length(maxlines)],"black")
ltp <- c(rep_len("solid",length(maxlines)),"longdash")
lines(seq_len(min_length),rep_len(worst_int, min_length),col=col[length(maxlines)+1],lty=ltp[length(maxlines)+1])
}
} else {
nam <- names(maxlines)
col <- colors[1:length(maxlines)]
ltp <- rep_len("solid",length(maxlines))
}
if (is.null(over_name)) {
legend("bottomright", legend=nam, col=col, lty=ltp)
} else {
legend("bottomright", legend=over_name, col=col, lty=ltp)
}
}
all_maxlines = c()
for (bn in BASENAMES) {
runtypefiles <- list.files(file.path(BENCHDIR,bn),pattern=sprintf("%s.[0-9]$",target),full.names = TRUE)
runtypefiles <- list.files(file.path(BENCHDIR,bn),pattern=sprintf(PATTERNS,target),full.names = TRUE)
if (length(runtypefiles) > 0) {
runtypetables = lapply(runtypefiles, function(x) read.table(x, quote="\"", comment.char="", col.names=c(bn)))
runtypetables <- lapply(seq_len(length(runtypefiles)),
function(i)read.table(runtypefiles[[i]], quote="\"", comment.char="", col.names=c(sprintf("%s%d",bn,i))))
runtypetables = trim_data(runtypetables)
list_of_maxlines = data2maxlines(runtypetables)
mean_maxline<-Reduce(function(a,b) a+b,list_of_maxlines,0)/length(runtypetables)
all_maxlines=append(all_maxlines,mean_maxline)
tmp_frame <- Reduce(bind_cols, list_of_maxlines)
statframe <- bind_cols(rowMeans(tmp_frame),apply(tmp_frame, 1, sd),apply(tmp_frame, 1, min),apply(tmp_frame, 1, max))
names(statframe) <- c(bn, sprintf("%s_sd",bn), sprintf("%s_min",bn), sprintf("%s_max",bn))
all_maxlines = c(all_maxlines, list(round(statframe)))
#all_maxlines = append(all_maxlines, list_of_maxlines)
#mean_maxline<-Reduce(function(a,b) a+b,list_of_maxlines,0)/length(runtypetables)
#all_maxlines=append(all_maxlines,mean_maxline)
}
}
min_length <- min(sapply(all_maxlines, length))
all_maxlines=lapply(all_maxlines, function(v) v[1:min_length])
min_length <- min(sapply(all_maxlines, function(x) dim(x)[1]))
all_maxlines=lapply(all_maxlines, function(v) v[1:min_length,])
one_frame<-data.frame(all_maxlines)
one_frame[length(one_frame)+1] <- seq_len(length(one_frame[[1]]))
names(one_frame)[length(one_frame)] <- 'iters'
ylow=min(one_frame[1:length(one_frame)-1])
yhigh=max(one_frame[1:length(one_frame)-1])
plot(c(1,length(one_frame[[1]])),c(ylow,yhigh), col='white', xlab="iters", ylab="wcet", pch='.')
typenames = names(one_frame)[which(names(one_frame) != 'iters')]
typenames = typenames[which(!endsWith(typenames, "_sd"))]
ylow=min(one_frame[typenames])
yhigh=max(one_frame[typenames])
plotting <- function(selection, filename, MY_COLORS_) {
# filter out names of iters and sd cols
typenames = names(one_frame)[which(names(one_frame) != 'iters')]
typenames = typenames[which(!endsWith(typenames, "_sd"))]
typenames = typenames[which(!endsWith(typenames, "_min"))]
typenames = typenames[which(!endsWith(typenames, "_max"))]
typenames = selection[which(selection %in% typenames)]
if (length(typenames) == 0) {return()}
h_ = 300
w_ = h_*4/3
if (SAVE_FILE) {png(file=sprintf("%s%s_%s.png",outputpath,target,filename), width=w_, height=h_)}
par(mar=c(4,4,1,1))
par(oma=c(0,0,0,0))
plot(c(1,length(one_frame[[1]])),c(ylow,yhigh), col='white', xlab="Iters", ylab="WORT", pch='.')
for (t in seq_len(length(typenames))) {
points(one_frame[c('iters',typenames[t])], col=myolors[t], pch='.')
proj = one_frame[seq(1, dim(one_frame)[1], by=200),]
points(proj[c('iters',typenames[t])], col=MY_COLORS_[t], pch='.')
if (exists("RIBBON") && RIBBON=='both') {
points(proj[c('iters',sprintf("%s_min",typenames[t]))], col=MY_COLORS_[t], pch='.')
points(proj[c('iters',sprintf("%s_max",typenames[t]))], col=MY_COLORS_[t], pch='.')
}
for (i in seq_len(dim(proj)[1])) {
row = proj[i,]
x_ <- row['iters'][[1]]
y_ <- row[typenames[t]][[1]]
sd_ <- row[sprintf("%s_sd",typenames[t])][[1]]
min_ <- row[sprintf("%s_min",typenames[t])][[1]]
max_ <- row[sprintf("%s_max",typenames[t])][[1]]
if (exists("RIBBON")) {
switch (RIBBON,
'sd' = arrows(x_, y_-sd_, x_, y_+sd_, length=0, angle=90, code=3, col=alpha(MY_COLORS_[t], alpha=0.05)),
'both' = arrows(x_, y_-sd_, x_, y_+sd_, length=0, angle=90, code=3, col=alpha(MY_COLORS_[t], alpha=0.1)),
'span' = arrows(x_, min_, x_, max_, length=0, angle=90, code=3, col=alpha(MY_COLORS_[t], alpha=0.05))
)
}
#arrows(x_, y_-sd_, x_, y_+sd_, length=0.05, angle=90, code=3, col=alpha(MY_COLORS[t], alpha=0.1))
}
}
legend("bottomright", legend=typenames, col=MY_COLORS_, lty="solid")
if (SAVE_FILE) {dev.off()}
}
par(mar=c(3.8,3.8,0,0))
par(oma=c(0,0,0,0))
if (exists("MY_SELECTION")) {
plotting(MY_SELECTION, 'custom', MY_COLORS)
} else {
MY_SELECTION=c('state', 'afl', 'graph', 'random', 'feedlongest')
RIBBON=''
plotting(MY_SELECTION,'all', MY_COLORS)
RIBBON='both'
for (i in seq_len(length(MY_SELECTION))) {
n <- MY_SELECTION[i]
plotting(c(n), n, c(MY_COLORS[i]))
}
}
legend("bottomright", legend=typenames, col=myolors, lty="solid")