Completely overhauled plot script
Completely overhauled plot script

NTAP/warpcore,NTAP/warpcore,NTAP/warpcore,NTAP/warpcore
#! /usr/bin/env Rscript

library(ggplot2)
library(data.table)
library(tools)
library(scales)

options(width=255)

files <- list.files(pattern=".*ping.*.txt")

my_fread <-function(file) {
    item <- fread(file)
    tags <- strsplit(file_path_sans_ext(file), "[-.]")[[1]]
    item$file <- file
    item$method <- tags[1]
    item$speed <- tags[2]
    item$busywait <- if (tags[3] %in% "b") "busy-wait" else "poll()"
    item$zcksum <-
        if (tags[3] %in% "z" | tags[4] %in% "z") "zero-checksum" else "checksum"
    # drop the first measurement, as it is often artificially long
    item <- item[-1,]
    return(item)
}

l <- lapply(files, my_fread)
dt <- rbindlist(l)

speed_labeller <- function(string) { return(paste0(string, "G")) }

method_labeller <- function(string) {
  return(ifelse(string == "shimping", "Kernel Stack", "Warpcore"))
}

gbps <- function(bytepnsec) { return(comma(bytepnsec*8)) }

usec <- function(nsec) { return(comma(nsec/1000)) }

mpps <- function(ppnsec) { return(comma(ppnsec*1000)) }


myplot <- function(dt, x, y, xlabel, ylabel, ymax, ylabeller) {
  theme <- theme(
          axis.line.x=element_line(size=0.2, colour="#777777"),
          axis.line.y=element_line(size=0.2, colour="#777777"),
          axis.text=element_text(family="Times", size=7, color="black"),
          axis.ticks.x=element_line(colour="#777777", size=.2),
          axis.ticks.y=element_line(colour="#777777", size=.2),
          axis.title=element_text(family="Times", size=7, color="black"),
          legend.background=element_blank(),
          legend.key.height=unit(7, "pt"),
          legend.key.width=unit(7, "mm"),
          legend.key=element_blank(),
          legend.position=c(.12, .9),
          legend.text=element_text(family="Times", size=7, color="black"),
          legend.title=element_blank(),
          panel.background=element_blank(),
          panel.spacing=unit(0.15, "in"),
          strip.background=element_rect(colour="white", fill="white"),
          panel.grid.major.x=element_line(colour="#777777", size=.2,
                                          linetype="dotted"),
          panel.grid.major.y=element_line(colour="#777777", size=.2,
                                          linetype="dotted"),
          plot.margin=unit(c(0, 0, 0, 0), "mm"),
          strip.text=element_text(family="Times", size=7, color="black"),
          text=element_text(family="Times", size=7, color="black")
  )

  dt$group <- paste(dt$busywait, "+", dt$zcksum)
  q25 <- function(x) {quantile(x, probs=0.25)}
  q75 <- function(x) {quantile(x, probs=0.75)}
  plot <- ggplot(data=dt, aes_string(x=x, y=y, shape="group", color="group")) +
          facet_grid(method ~ speed,
                     labeller=labeller(speed=speed_labeller,
                                       method=method_labeller)) +
          geom_smooth(size=.5, alpha=.25, method="loess") +
          # stat_summary(fun.y=median, fun.ymin=q25, fun.ymax=q75, size=.25) +
          stat_summary(fun.data=mean_se, size=.25) +
          scale_colour_brewer(type="div", palette="PuOr", drop=FALSE) +
          scale_x_continuous(labels=comma, expand=c(0, 0), limit=c(0, NA),
                             name=xlabel) +
          scale_y_continuous(labels=ylabeller, expand=c(0, 0),
                             limit=c(0, ymax), name=ylabel)
    return(plot + theme)
}


common <- c()

ggsave(plot=myplot(dt, "byte", "rx", "UDP Payload Size [B]",
                   expression(paste("RTT [", mu, "s]")), NA, usec),
       height=2.75, width=7.15, units="in", filename="latency.pdf")

ggsave(plot=myplot(dt, "byte", "byte/rx", "UDP Payload Size [B]",
                   "Throughput [GB/s]", NA, gbps),
       height=2.75, width=7.15, units="in", filename="thruput.pdf")

ggsave(plot=myplot(dt, "pkts", "pkts/tx", "Packets [#]",
                   "Packets/Second [Mpps]", NA, mpps),
       height=2.75, width=7.15, units="in", filename="pps.pdf")

short <- dt[dt$byte < 1600]

ggsave(plot=myplot(short, "byte", "rx", "UDP Payload Size [B]",
                   expression(paste("RTT [", mu, "s]")), NA, usec),
       height=2.75, width=7.15, units="in", filename="latency-1500.pdf")

ggsave(plot=myplot(short, "byte", "byte/rx", "UDP Payload Size [B]",
                   "Throughput [GB/s]", NA, gbps),
       height=2.75, width=7.15, units="in", filename="thruput-1500.pdf")

#! /usr/bin/env Rscript

library(ggplot2)
library(data.table)
library(tools)

files <- list.files(pattern=".*ping.*.txt")

my_fread <-function(file) {
    item <- fread(file)
    tags <- strsplit(file_path_sans_ext(file), "[-.]")[[1]]
    item$file <- file
    item$method <- tags[1]
    item$speed <- tags[2]
    item$busywait <- if (tags[3] %in% "b") "busy-wait" else "poll()"
    item$zcksum <-
        if (tags[3] %in% "z" | tags[4] %in% "z") "zero-checksum" else "checksum"
    return (item)
}

l <- lapply(files, my_fread)
dt <- rbindlist(l)
dt[, usec:=nsec/1000]

stats <- dt[, list(n=length(usec), min=min(usec), max=max(usec),
                   mean=mean(usec), sd=sd(usec), median=as.double(median(usec)),
                   q1=quantile(usec, probs=c(.01)),
                   q25=quantile(usec, probs=c(.25)),
                   q75=quantile(usec, probs=c(.75)),
                   q99=quantile(usec, probs=c(.99))),
            by=list(method, speed, busywait, zcksum, size)]

stats <- stats[stats$method != "shimping" | stats$zcksum != "zero-checksum"]

# ggplot(data=dt, aes(x=size, y=usec, color=file)) + ylim(0, 100) +
#   geom_point(size=.5)


speed_labeller <- function(string) {
  return(paste(string, "G", sep = ""))
}


method_labeller <- function(string) {
  return(ifelse(string == "shimping", "Kernel Stack", "Warpcore"))
}


my_plot<- function(dt, ymax, legend) {
    theme <- theme(
            axis.line.x=element_line(size=0.2, colour="#777777"),
            axis.line.y=element_line(size=0.2, colour="#777777"),
            axis.text=element_text(family="Times", size=7, color="black"),
            axis.ticks.x=element_line(colour="#777777", size=.2),
            axis.ticks.y=element_line(colour="#777777", size=.2),
            # axis.title.x=element_text(margin=margin(-.05, 0, 0, 0)),
            # axis.title.y=element_text(margin=margin(0, -.05, 0, 0)),
            axis.title=element_text(family="Times", size=7, color="black"),
            legend.background=element_blank(),
            legend.key.height=unit(7, "pt"),
            legend.key.width=unit(7, "mm"),
            legend.key=element_blank(),
            legend.position=if (legend) c(.18, .65) else "none",
            legend.text=element_text(family="Times", size=7, color="black"),
            legend.title=element_blank(),
            panel.background=element_blank(),
            panel.spacing=unit(0.15, "in"),
            strip.background=element_rect(colour="white", fill="white"),
            panel.grid.major.x=element_line(colour="#777777", size=.2,
                                            linetype="dotted"),
            panel.grid.major.y=element_line(colour="#777777", size=.2,
                                            linetype="dotted"),
            plot.margin=unit(c(0, 0, 0, 0), "mm"),
            strip.text=element_text(family="Times", size=7, color="black"),
            text=element_text(family="Times", size=7, color="black")
    )

    plot <- ggplot(data=dt, aes(x=size, y=median,
                                   shape=paste(busywait, "+", zcksum),
                                   color=paste(busywait, "+", zcksum))) +
            facet_grid(method ~ speed,
                       labeller=labeller(speed=speed_labeller,
                                         method=method_labeller)) +
            geom_errorbar(aes(ymin=q25, ymax=q75), linetype="solid", size=.25,
                          # position=position_dodge(width=20)
                          width=20) +
            geom_line(size=.5) +
            geom_point(size=1) +
            scale_colour_brewer(type="div", palette="PuOr", drop=FALSE) +
            scale_x_continuous(expand=c(0, 0), limit=c(0, 1551),
                               name="UDP Payload Size [B]") +
            scale_y_continuous(expand=c(0, 0), limit=c(0, ymax),
                               name=expression(paste("Median RTT [", mu, "s]")))
    return (plot + theme)
}

ggsave(plot=my_plot(stats, 50, TRUE),
       height=2.75, width=7.15, units="in",
       filename=paste("combined.pdf", sep=""))

# legend <- TRUE
# for (s in unique(stats$speed)) {
#     for (m in unique(stats$method)) {
#         fstats <- stats[stats$speed == s & stats$method == m]
#         ymax <- if(s == 1 & m == "shimping") NA
#                 else max(stats$q99[stats$method != "shimping"])
#         ggsave(plot=my_plot(stats, ymax, legend),
#                height=1.3, width=3.5, units="in",
#                filename=paste(m, "-", s, ".pdf", sep=""))
#         legend <- FALSE
#     }
# }
