Skip to content

Commit

Permalink
[benchmarks/wedge] Basic ggplot2() working
Browse files Browse the repository at this point in the history
Need to figure out time intervals and xargs_slot.
  • Loading branch information
Andy C committed Jan 27, 2024
1 parent 83adf0e commit 451f209
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 14 deletions.
63 changes: 55 additions & 8 deletions benchmarks/wedge.R
Expand Up @@ -6,26 +6,72 @@
# wedge.R ACTION IN_DIR OUT_DIR

library(dplyr)
# Hm this isn't available
#library(ggplot2)
library(ggplot2)

source('benchmarks/common.R')

options(stringsAsFactors = F,
# Make the report wide. tibble.width doesn't appear to do this?
width=200,
tibble.print_max=Inf
#tibble.print_max=Inf,

# for printing of timestamps
digits=11
)

Report = function(ctx) {
print(ctx$tasks)
Log('hi')
WritePlot <- function(p, filename, width = 800, height = 600) {
png(filename, width=width, height=height)
plot(p)
dev.off()
Log('Wrote %s', filename)
}

PlotElapsed <- function(ctx) {
g <- ggplot(ctx$tasks, aes(x = wedge, y = elapsed_secs))

# NOTE: stat = "identity" required for x and y, geom_bar makes a histogram by
# default
b <- geom_bar(stat = "identity")
t <- ggtitle('Elapsed Time')

g + b + t #+ scale_fill_manual(values=palette)
}

PlotXargs <- function(ctx) {
tasks = ctx$tasks

print(tasks)

# Not sure why I have to supply origin
tasks$start_time = as.POSIXct(tasks$start_time, origin='1970-01-01')
tasks$end_time = as.POSIXct(tasks$end_time, origin='1970-01-01')

g <- ggplot(ctx$tasks, aes(x = wedge, y = end_time))

# NOTE: stat = "identity" required for x and y, geom_bar makes a histogram by
# default
b <- geom_bar(stat = "identity")
t <- ggtitle('xargs slots')

g + b + t #+ scale_fill_manual(values=palette)
}

# TODO: geom_segment for start and end?
# with xargs_slot
#
# Something like this
# https://stackoverflow.com/questions/70767351/plotting-date-intervals-in-ggplot2

Report = function(ctx) {
p = PlotElapsed(ctx)

out_dir = '_build/wedge'

p = PlotElapsed(ctx)
WritePlot(p, file.path(out_dir, 'elapsed.png'))

p = PlotXargs(ctx)
WritePlot(p, file.path(out_dir, 'xargs.png'))
}

Load = function(in_dir) {
Expand All @@ -39,7 +85,8 @@ main = function(argv) {

if (action == 'xargs-report') {
in_dir = argv[[2]]
out_dir = argv[[3]]
#out_dir = argv[[3]]

ctx = Load(in_dir)
Report(ctx)

Expand All @@ -51,6 +98,6 @@ main = function(argv) {

if (length(sys.frames()) == 0) {
# increase ggplot font size globally
#theme_set(theme_grey(base_size = 20))
theme_set(theme_grey(base_size = 20))
main(commandArgs(TRUE))
}
27 changes: 21 additions & 6 deletions benchmarks/wedge.sh
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#
# Analyze how mycpp speeds up programs.
# Analyze wedge build on Soil CI.
#
# Usage:
# benchmarks/mycpp.sh <function name>
# benchmarks/wedge.sh <function name>

set -o nounset
set -o pipefail
Expand All @@ -12,12 +12,27 @@ set -o errexit
REPO_ROOT=$(cd $(dirname $0)/.. && pwd)
readonly REPO_ROOT

source build/dev-shell.sh # R_LIBS_USER
#source soil/common.sh # find-dir-html
#source test/tsv-lib.sh # tsv2html
#source build/dev-shell.sh # R_LIBS_USER


# Keeping ggplot2 out of the wedge until this works
install-R-packages() {
mkdir -p ~/R
INSTALL_DEST=~/R Rscript -e \
'install.packages(c("dplyr", "ggplot2", "RUnit"), lib=Sys.getenv("INSTALL_DEST"), repos="https://cloud.r-project.org")'
}

readonly DIR=_tmp/wedge

download-tsv() {
mkdir -p $DIR
wget --directory-prefix $DIR \
http://travis-ci.oilshell.org/github-jobs/6022/dev-setup-debian.wwz/_build/wedge/logs/tasks.tsv
}

xargs-report() {
benchmarks/wedge.R xargs-report _build/wedge/logs
#R_LIBS_USER=~/R benchmarks/wedge.R xargs-report _build/wedge/logs
R_LIBS_USER=~/R benchmarks/wedge.R xargs-report $DIR
}

"$@"

0 comments on commit 451f209

Please sign in to comment.