Skip to content
This repository was archived by the owner on Sep 5, 2019. It is now read-only.

Commit 989eec1

Browse files
authored
Fixed a few concurrency issues (#22)
1 parent a5f13ed commit 989eec1

File tree

47 files changed

+9647
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+9647
-121
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
BenchmarkDotNetVersion <- "BenchmarkDotNet v0.11.1 "
2+
dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE, showWarnings = FALSE)
3+
list.of.packages <- c("ggplot2", "dplyr", "gdata", "tidyr", "grid", "gridExtra", "Rcpp")
4+
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
5+
if(length(new.packages)) install.packages(new.packages, lib = Sys.getenv("R_LIBS_USER"), repos = "http://cran.rstudio.com/")
6+
library(ggplot2)
7+
library(dplyr)
8+
library(gdata)
9+
library(tidyr)
10+
library(grid)
11+
library(gridExtra)
12+
13+
ends_with <- function(vars, match, ignore.case = TRUE) {
14+
if (ignore.case)
15+
match <- tolower(match)
16+
n <- nchar(match)
17+
18+
if (ignore.case)
19+
vars <- tolower(vars)
20+
length <- nchar(vars)
21+
22+
substr(vars, pmax(1, length - n + 1), length) == match
23+
}
24+
std.error <- function(x) sqrt(var(x)/length(x))
25+
cummean <- function(x) cumsum(x)/(1:length(x))
26+
BenchmarkDotNetVersionGrob <- textGrob(BenchmarkDotNetVersion, gp = gpar(fontface=3, fontsize=10), hjust=1, x=1)
27+
nicePlot <- function(p) grid.arrange(p, bottom = BenchmarkDotNetVersionGrob)
28+
printNice <- function(p) print(nicePlot(p))
29+
ggsaveNice <- function(fileName, p, ...) {
30+
cat(paste0("*** Plot: ", fileName, " ***\n"))
31+
ggsave(fileName, plot = nicePlot(p), ...)
32+
cat("------------------------------\n")
33+
}
34+
35+
args <- commandArgs(trailingOnly = TRUE)
36+
files <- if (length(args) > 0) args else list.files()[list.files() %>% ends_with("-measurements.csv")]
37+
for (file in files) {
38+
title <- gsub("-measurements.csv", "", basename(file))
39+
measurements <- read.csv(file, sep = ",")
40+
41+
result <- measurements %>% filter(Measurement_IterationStage == "Result")
42+
if (nrow(result[is.na(result$Job_Id),]) > 0)
43+
result[is.na(result$Job_Id),]$Job_Id <- ""
44+
if (nrow(result[is.na(result$Params),]) > 0) {
45+
result[is.na(result$Params),]$Params <- ""
46+
} else {
47+
result$Job_Id <- trim(paste(result$Job_Id, result$Params))
48+
}
49+
result$Job_Id <- factor(result$Job_Id, levels = unique(result$Job_Id))
50+
51+
timeUnit <- "ns"
52+
if (min(result$Measurement_Value) > 1000) {
53+
result$Measurement_Value <- result$Measurement_Value / 1000
54+
timeUnit <- "us"
55+
}
56+
if (min(result$Measurement_Value) > 1000) {
57+
result$Measurement_Value <- result$Measurement_Value / 1000
58+
timeUnit <- "ms"
59+
}
60+
if (min(result$Measurement_Value) > 1000) {
61+
result$Measurement_Value <- result$Measurement_Value / 1000
62+
timeUnit <- "sec"
63+
}
64+
65+
resultStats <- result %>%
66+
group_by_(.dots = c("Target_Method", "Job_Id")) %>%
67+
summarise(se = std.error(Measurement_Value), Value = mean(Measurement_Value))
68+
69+
benchmarkBoxplot <- ggplot(result, aes(x=Target_Method, y=Measurement_Value, fill=Job_Id)) +
70+
guides(fill=guide_legend(title="Job")) +
71+
xlab("Target") +
72+
ylab(paste("Time,", timeUnit)) +
73+
ggtitle(title) +
74+
geom_boxplot()
75+
benchmarkBarplot <- ggplot(resultStats, aes(x=Target_Method, y=Value, fill=Job_Id)) +
76+
guides(fill=guide_legend(title="Job")) +
77+
xlab("Target") +
78+
ylab(paste("Time,", timeUnit)) +
79+
ggtitle(title) +
80+
geom_bar(position=position_dodge(), stat="identity")
81+
#geom_errorbar(aes(ymin=Value-1.96*se, ymax=Value+1.96*se), width=.2, position=position_dodge(.9))
82+
83+
printNice(benchmarkBoxplot)
84+
printNice(benchmarkBarplot)
85+
ggsaveNice(gsub("-measurements.csv", "-boxplot.png", file), benchmarkBoxplot)
86+
ggsaveNice(gsub("-measurements.csv", "-barplot.png", file), benchmarkBarplot)
87+
88+
for (target in unique(result$Target_Method)) {
89+
df <- result %>% filter(Target_Method == target)
90+
df$Launch <- factor(df$Measurement_LaunchIndex)
91+
df <- df %>% group_by(Job_Id, Launch) %>% mutate(cm = cummean(Measurement_Value))
92+
93+
densityPlot <- ggplot(df, aes(x=Measurement_Value, fill=Job_Id)) +
94+
ggtitle(paste(title, "/", target)) +
95+
xlab(paste("Time,", timeUnit)) +
96+
geom_density(alpha=.5)
97+
printNice(densityPlot)
98+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-density.png"), file), densityPlot)
99+
100+
facetDensityPlot <- densityPlot + facet_wrap(~Job_Id)
101+
printNice(facetDensityPlot)
102+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-facetDensity.png"), file), facetDensityPlot)
103+
104+
for (params in unique(df$Params)) {
105+
paramsDf <- df %>% filter(Params == params)
106+
107+
paramsDensityPlot <- ggplot(paramsDf, aes(x=Measurement_Value, fill=Job_Id)) +
108+
ggtitle(paste(title, "/", target, "/", params)) +
109+
xlab(paste("Time,", timeUnit)) +
110+
geom_density(alpha=.5)
111+
printNice(paramsDensityPlot)
112+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-", params, "-density.png"), file), paramsDensityPlot)
113+
114+
paramsFacetDensityPlot <- paramsDensityPlot + facet_wrap(~Job_Id)
115+
printNice(paramsFacetDensityPlot)
116+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-", params, "-facetDensity.png"), file), paramsFacetDensityPlot)
117+
}
118+
119+
for (job in unique(df$Job_Id)) {
120+
jobDf <- df %>% filter(Job_Id == job)
121+
timelinePlot <- ggplot(jobDf, aes(x = Measurement_IterationIndex, y=Measurement_Value, group=Launch, color=Launch)) +
122+
ggtitle(paste(title, "/", target, "/", job)) +
123+
xlab("IterationIndex") +
124+
ylab(paste("Time,", timeUnit)) +
125+
geom_line() +
126+
geom_point()
127+
printNice(timelinePlot)
128+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-", job, "-timeline.png"), file), timelinePlot)
129+
timelinePlotSmooth <- timelinePlot + geom_smooth()
130+
printNice(timelinePlotSmooth)
131+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-", job, "-timelineSmooth.png"), file), timelinePlotSmooth)
132+
133+
cummeanPlot <- ggplot(jobDf, aes(x = Measurement_IterationIndex, y=cm, group=Launch, color=Launch)) +
134+
ggtitle(paste(title, "/", target, "/", job)) +
135+
xlab("IterationIndex") +
136+
ylab(paste("Cumulative mean time,", timeUnit)) +
137+
geom_line() +
138+
geom_point()
139+
printNice(cummeanPlot)
140+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-", job, "-cummean.png"), file), cummeanPlot)
141+
142+
143+
densityPlotJob <- ggplot(jobDf, aes(x=Measurement_Value, fill="red")) +
144+
ggtitle(paste(title, "/", target, "/", job)) +
145+
xlab(paste("Time,", timeUnit)) +
146+
geom_density(alpha=.5)
147+
printNice(densityPlotJob)
148+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-", job, "-density.png"), file), densityPlotJob)
149+
}
150+
151+
timelinePlot <- ggplot(df, aes(x = Measurement_IterationIndex, y=Measurement_Value, group=Launch, color=Launch)) +
152+
ggtitle(paste(title, "/", target)) +
153+
xlab("IterationIndex") +
154+
ylab(paste("Time,", timeUnit)) +
155+
geom_line() +
156+
geom_point() +
157+
facet_wrap(~Job_Id)
158+
printNice(timelinePlot)
159+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-facetTimeline.png"), file), timelinePlot)
160+
timelinePlotSmooth <- timelinePlot + geom_smooth()
161+
printNice(timelinePlotSmooth)
162+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-facetTimelineSmooth.png"), file), timelinePlotSmooth)
163+
164+
facetCummeanPlot <- ggplot(df, aes(x = Measurement_IterationIndex, y=cm, group=Launch, color=Launch)) +
165+
ggtitle(paste(title, "/", target)) +
166+
xlab("IterationIndex") +
167+
ylab(paste("Cumulative mean time,", timeUnit)) +
168+
geom_line() +
169+
geom_point() +
170+
facet_wrap(~Job_Id)
171+
printNice(facetCummeanPlot)
172+
ggsaveNice(gsub("-measurements.csv", paste0("-", target, "-cummean.png"), file), facetCummeanPlot)
173+
}
174+
}

0 commit comments

Comments
 (0)