-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.R
94 lines (82 loc) · 2.94 KB
/
script.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
suppressPackageStartupMessages(library(optparse))
# Example data rows, one per test iteration:
# data[1:2,]
# V1 V2 V3
# 1 XSAVE_DIRTY_RSTOR baseline 33
# 2 XSAVE_DIRTY_RSTOR baseline 35
#
# levels(data$V1) (these are the test types)
# [1] "RSTOR_DIRTY_XSAVE" "RSTOR_DIRTY_XSAVEOPT" "XSAVE_DIRTY_RSTOR"
# [4] "XSAVEOPT_DIRTY_RSTOR"
#
# levels(data$V2) (these are the type of dirtying)
# [1] "all" "baseline" "fpu" "xmm"
### build a vector like c(1,2,3,4, 7,8,9,10, ...) to space the tests
vec_spacing <- function(d) {
spacing <- c()
pos <- 1
for (i in 1:length(levels(d$V1))) {
for (j in 1:length(levels(d$V2))) {
spacing <- append(spacing, pos)
pos <- pos + 1
}
pos <- pos + 2
}
return(spacing)
}
# Finds the FOO after 'pattern' from a line in infile, e.g. "patternFOO".
# There's probably an R helper for this.
extract_meta_val <- function(infile, pattern)
{
lines <- readLines(infile)
titular_line <- grep(pattern, lines, value = TRUE)
idx <- attr(regexpr(pattern, titular_line), "match.length") + 1
return(substr(titular_line, idx, nchar(titular_line)))
}
get_title <- function(infile) {
return(extract_meta_val(infile, "# title: "))
}
get_machine <- function(infile) {
return(extract_meta_val(infile, "# machine: "))
}
### collect command line arguments
# establish optional arguments
# "-h" and "--help" are automatically in the list
option_list <- list(
make_option(c("-i", "--input"), type = "character",
default = "raw.dat",
help = "Input data file"),
make_option(c("-o", "--output"), type = "character",
default = "graph.pdf",
help = "Output file"),
make_option("--ymin", type = "double", default = 0),
make_option("--ymax", type = "double", default = -1)
)
opt <- parse_args(OptionParser(option_list=option_list))
data <- read.table(opt$input)
title <- get_title(opt$input)
machine <- get_machine(opt$input)
plot_header <- paste(title, machine, sep = '\n')
# probably better ways to do this automatically (without the opts)
ymax <- max(data$V3)
if (opt$ymax != -1) {
ymax = min(opt$ymax, ymax)
}
pdf(opt$output)
# Hacked values for our x labels, after rotation
par(mar = c(16,4,4,2))
# Fixed-width font to easily align x axis values
par(family = "mono")
# This sorts the tests factors into the order they appear in the input
tests_f <- factor(data$V1, levels = unique(c(levels(data$V1)[data$V1])))
# This sorts the dirty factors into the order they appear in the input
dirty_f <- factor(data$V2, levels = unique(c(levels(data$V2)[data$V2])))
# lex.order = TRUE will group them by test type
factors <- interaction(tests_f, dirty_f, lex.order = TRUE)
# to do points instead of a boxplot, for boxplot, set border = "white" and then:
# points(interaction(data$V1, data$V2), data$V3)
spacing <- vec_spacing(data)
boxplot(data$V3 ~ factors, las = 2, main = plot_header, ylim = c(opt$ymin,ymax),
at = spacing, cex.axis = 0.5, ylab = "Unhalted Core Cycles")
abline(v = spacing, lty = 3, col = "grey")
invisible(dev.off())