| 1 | #!/usr/bin/env Rscript
 | 
| 2 | #
 | 
| 3 | # wedge.R -- Show how long it takes
 | 
| 4 | #
 | 
| 5 | # Usage:
 | 
| 6 | #   wedge.R ACTION IN_DIR OUT_DIR
 | 
| 7 | 
 | 
| 8 | library(dplyr)
 | 
| 9 | library(ggplot2)
 | 
| 10 | 
 | 
| 11 | source('benchmarks/common.R')
 | 
| 12 | 
 | 
| 13 | options(stringsAsFactors = F,
 | 
| 14 |         # Make the report wide.  tibble.width doesn't appear to do this?
 | 
| 15 |         width=200,
 | 
| 16 |         #tibble.print_max=Inf,
 | 
| 17 | 
 | 
| 18 |         # for printing of timestamps
 | 
| 19 |         digits=11
 | 
| 20 | )
 | 
| 21 | 
 | 
| 22 | WritePlot <- function(p, filename, width = 800, height = 600) {
 | 
| 23 |   png(filename, width=width, height=height)
 | 
| 24 |   plot(p)
 | 
| 25 |   dev.off()
 | 
| 26 |   Log('Wrote %s', filename)
 | 
| 27 | }
 | 
| 28 | 
 | 
| 29 | PlotElapsed <- function(ctx) {
 | 
| 30 |   g <- ggplot(ctx$tasks, aes(x = wedge, y = elapsed_secs))
 | 
| 31 | 
 | 
| 32 |   # NOTE: stat = "identity" required for x and y, geom_bar makes a histogram by
 | 
| 33 |   # default
 | 
| 34 |   b <- geom_bar(stat = "identity")
 | 
| 35 |   t <- ggtitle('Elapsed Time')
 | 
| 36 | 
 | 
| 37 |   g + b + t #+ scale_fill_manual(values=palette)
 | 
| 38 | }
 | 
| 39 | 
 | 
| 40 | PlotXargs <- function(ctx) {
 | 
| 41 |   tasks = ctx$tasks
 | 
| 42 | 
 | 
| 43 |   left = min(tasks$start_time)
 | 
| 44 |   Log("Starting at %f", left)
 | 
| 45 | 
 | 
| 46 |   tasks$start_time = tasks$start_time - left
 | 
| 47 |   tasks$end_time = tasks$end_time - left
 | 
| 48 |   #print(tasks)
 | 
| 49 | 
 | 
| 50 |   g = ggplot(tasks, aes(x = start_time, xend = end_time, y = xargs_slot, yend = xargs_slot))
 | 
| 51 |   line = geom_segment(linewidth = 10, aes(color = wedge))
 | 
| 52 |   labs = labs(title = "Parallel Wedge Builds", x = "time (seconds)", y = "xargs slot")
 | 
| 53 | 
 | 
| 54 |   g + line + labs
 | 
| 55 | 
 | 
| 56 |   # Doesn't work
 | 
| 57 |   #+ scale_x_time()
 | 
| 58 | }
 | 
| 59 | 
 | 
| 60 | # Something like this
 | 
| 61 | # https://stackoverflow.com/questions/70767351/plotting-date-intervals-in-ggplot2
 | 
| 62 | 
 | 
| 63 | Report = function(ctx, out_dir) {
 | 
| 64 |   p = PlotElapsed(ctx)
 | 
| 65 | 
 | 
| 66 |   p = PlotElapsed(ctx)
 | 
| 67 |   WritePlot(p, file.path(out_dir, 'elapsed.png'))
 | 
| 68 | 
 | 
| 69 |   p = PlotXargs(ctx)
 | 
| 70 |   WritePlot(p, file.path(out_dir, 'xargs.png'))
 | 
| 71 | }
 | 
| 72 | 
 | 
| 73 | Load = function(in_dir) {
 | 
| 74 |   list(tasks = read.table(file.path(in_dir, 'tasks.tsv'), header=T))
 | 
| 75 | }
 | 
| 76 | 
 | 
| 77 | main = function(argv) {
 | 
| 78 |   action = argv[[1]]
 | 
| 79 | 
 | 
| 80 |   if (action == 'xargs-report') {
 | 
| 81 |     in_dir = argv[[2]]
 | 
| 82 |     out_dir = in_dir  # same for now
 | 
| 83 | 
 | 
| 84 |     ctx = Load(in_dir)
 | 
| 85 |     Report(ctx, out_dir)
 | 
| 86 | 
 | 
| 87 |   } else {
 | 
| 88 |     Log("Invalid action '%s'", action)
 | 
| 89 |     quit(status = 1)
 | 
| 90 |   }
 | 
| 91 | }
 | 
| 92 | 
 | 
| 93 | if (length(sys.frames()) == 0) {
 | 
| 94 |   # increase ggplot font size globally
 | 
| 95 |   theme_set(theme_grey(base_size = 20))
 | 
| 96 |   main(commandArgs(TRUE))
 | 
| 97 | }
 |