OILS / benchmarks / report.R View on Github | oilshell.org

1339 lines, 928 significant
1#!/usr/bin/env Rscript
2#
3# benchmarks/report.R -- Analyze data collected by shell scripts.
4#
5# Usage:
6# benchmarks/report.R OUT_DIR [TIMES_CSV...]
7
8# Suppress warnings about functions masked from 'package:stats' and 'package:base'
9# filter, lag
10# intersect, setdiff, setequal, union
11library(dplyr, warn.conflicts = FALSE)
12library(tidyr) # spread()
13library(stringr)
14
15source('benchmarks/common.R')
16
17options(stringsAsFactors = F)
18
19# For pretty printing
20commas = function(x) {
21 format(x, big.mark=',')
22}
23
24sourceUrl = function(path) {
25 sprintf('https://github.com/oilshell/oil/blob/master/%s', path)
26}
27
28# Takes a filename, not a path.
29sourceUrl2 = function(filename) {
30 sprintf(
31 'https://github.com/oilshell/oil/blob/master/benchmarks/testdata/%s',
32 filename)
33}
34
35mycppUrl = function(path) {
36 sprintf('https://github.com/oilshell/oil/blob/master/mycpp/examples/%s.py', path)
37}
38
39
40# TODO: Set up cgit because Github links are slow.
41benchmarkDataLink = function(subdir, name, suffix) {
42 #sprintf('../../../../benchmark-data/shell-id/%s', shell_id)
43 sprintf('https://github.com/oilshell/benchmark-data/blob/master/%s/%s%s',
44 subdir, name, suffix)
45}
46
47provenanceLink = function(subdir, name, suffix) {
48 sprintf('../%s/%s%s', subdir, name, suffix)
49}
50
51
52GetOshLabel = function(shell_hash, prov_dir) {
53 ### Given a string, return another string.
54
55 path = sprintf('%s/shell-id/osh-%s/sh-path.txt', prov_dir, shell_hash)
56
57 if (file.exists(path)) {
58 Log('Reading %s', path)
59 lines = readLines(path)
60 if (length(grep('_bin/osh', lines)) > 0) {
61 label = 'osh-ovm'
62 } else if (length(grep('bin/osh', lines)) > 0) {
63 label = 'osh-cpython'
64 } else if (length(grep('_bin/.*/osh', lines)) > 0) {
65 label = 'osh-native'
66 } else {
67 stop("Expected _bin/osh, bin/osh, or _bin/.*/osh")
68 }
69 } else {
70 stop(sprintf("%s doesn't exist", path))
71 }
72 return(label)
73}
74
75opt_suffix1 = '_bin/cxx-opt/osh'
76opt_suffix2 = '_bin/cxx-opt-sh/osh'
77
78ShellLabels = function(shell_name, shell_hash, num_hosts) {
79 ### Given 2 vectors, return a vector of readable labels.
80
81 # TODO: Clean up callers. Some metrics all this function with a
82 # shell/runtime BASENAME, and others a PATH
83 # - e.g. ComputeReport calls this with runtime_name which is actually a PATH
84
85 #Log('name %s', shell_name)
86 #Log('hash %s', shell_hash)
87
88 if (num_hosts == 1) {
89 prov_dir = '_tmp'
90 } else {
91 prov_dir = '../benchmark-data/'
92 }
93
94 labels = c()
95 for (i in 1:length(shell_name)) {
96 sh = shell_name[i]
97 if (sh == 'osh') {
98 label = GetOshLabel(shell_hash[i], prov_dir)
99
100 } else if (endsWith(sh, opt_suffix1) || endsWith(sh, opt_suffix2)) {
101 label = 'opt/osh'
102
103 } else if (endsWith(sh, '_bin/cxx-opt+bumpleak/osh')) {
104 label = 'bumpleak/osh'
105
106 } else {
107 label = sh
108 }
109
110 Log('[%s] [%s]', shell_name[i], label)
111 labels = c(labels, label)
112 }
113
114 return(labels)
115}
116
117# Simple version of the above, used by benchmarks/gc
118ShellLabelFromPath = function(sh_path) {
119 labels = c()
120 for (i in 1:length(sh_path)) {
121 sh = sh_path[i]
122
123 if (endsWith(sh, opt_suffix1) || endsWith(sh, opt_suffix2)) {
124 # the opt binary is osh-native
125 label = 'osh-native'
126
127 } else if (endsWith(sh, '_bin/cxx-opt+bumpleak/osh')) {
128 label = 'bumpleak/osh'
129
130 } else if (endsWith(sh, '_bin/osh')) { # the app bundle
131 label = 'osh-ovm'
132
133 } else if (endsWith(sh, 'bin/osh')) {
134 label = 'osh-cpython'
135
136 } else {
137 label = sh
138 }
139 labels = c(labels, label)
140 }
141 return(labels)
142}
143
144DistinctHosts = function(t) {
145 t %>% distinct(host_name, host_hash) -> distinct_hosts
146 # The label is just the name
147 distinct_hosts$host_label = distinct_hosts$host_name
148 return(distinct_hosts)
149}
150
151DistinctShells = function(t, num_hosts = -1) {
152 t %>% distinct(shell_name, shell_hash) -> distinct_shells
153
154 Log('')
155 Log('Labeling shells')
156
157 # Calculate it if not passed
158 if (num_hosts == -1) {
159 num_hosts = nrow(DistinctHosts(t))
160 }
161
162 distinct_shells$shell_label = ShellLabels(distinct_shells$shell_name,
163 distinct_shells$shell_hash,
164 num_hosts)
165 return(distinct_shells)
166}
167
168ParserReport = function(in_dir, out_dir) {
169 times = read.csv(file.path(in_dir, 'times.csv'))
170 lines = read.csv(file.path(in_dir, 'lines.csv'))
171 raw_data = read.csv(file.path(in_dir, 'raw-data.csv'))
172
173 cachegrind = readTsv(file.path(in_dir, 'cachegrind.tsv'))
174
175 # For joining by filename
176 lines_by_filename = tibble(
177 num_lines = lines$num_lines,
178 filename = basename(lines$path)
179 )
180
181 # Remove failures
182 times %>% filter(status == 0) %>% select(-c(status)) -> times
183 cachegrind %>% filter(status == 0) %>% select(-c(status)) -> cachegrind
184
185 # Add the number of lines, joining on path, and compute lines/ms
186 times %>%
187 left_join(lines, by = c('path')) %>%
188 mutate(filename = basename(path), filename_HREF = sourceUrl(path),
189 max_rss_MB = max_rss_KiB * 1024 / 1e6,
190 elapsed_ms = elapsed_secs * 1000,
191 user_ms = user_secs * 1000,
192 sys_ms = sys_secs * 1000,
193 lines_per_ms = num_lines / elapsed_ms) %>%
194 select(-c(path, max_rss_KiB, elapsed_secs, user_secs, sys_secs)) ->
195 joined_times
196
197 #print(head(times))
198 #print(head(lines))
199 #print(head(vm))
200 #print(head(joined_times))
201
202 print(summary(joined_times))
203
204 #
205 # Find distinct shells and hosts, and label them for readability.
206 #
207
208 distinct_hosts = DistinctHosts(joined_times)
209 Log('')
210 Log('Distinct hosts')
211 print(distinct_hosts)
212
213 distinct_shells = DistinctShells(joined_times)
214 Log('')
215 Log('Distinct shells')
216 print(distinct_shells)
217
218 # Replace name/hash combinations with labels.
219 joined_times %>%
220 left_join(distinct_hosts, by = c('host_name', 'host_hash')) %>%
221 left_join(distinct_shells, by = c('shell_name', 'shell_hash')) %>%
222 select(-c(host_name, host_hash, shell_name, shell_hash)) ->
223 joined_times
224
225 # Like 'times', but do shell_label as one step
226 # Hack: we know benchmarks/auto.sh runs this on one machine
227 distinct_shells_2 = DistinctShells(cachegrind, num_hosts = nrow(distinct_hosts))
228 cachegrind %>%
229 left_join(lines, by = c('path')) %>%
230 select(-c(elapsed_secs, user_secs, sys_secs, max_rss_KiB)) %>%
231 left_join(distinct_shells_2, by = c('shell_name', 'shell_hash')) %>%
232 select(-c(shell_name, shell_hash)) %>%
233 mutate(filename = basename(path), filename_HREF = sourceUrl(path)) %>%
234 select(-c(path)) ->
235 joined_cachegrind
236
237 Log('summary(joined_times):')
238 print(summary(joined_times))
239 Log('head(joined_times):')
240 print(head(joined_times))
241
242 # Summarize rates by platform/shell
243 joined_times %>%
244 mutate(host_label = paste("host", host_label)) %>%
245 group_by(host_label, shell_label) %>%
246 summarize(total_lines = sum(num_lines), total_ms = sum(elapsed_ms)) %>%
247 mutate(lines_per_ms = total_lines / total_ms) %>%
248 select(-c(total_ms)) %>%
249 spread(key = host_label, value = lines_per_ms) ->
250 times_summary
251
252 # Sort by parsing rate on the fast machine
253 if ("host lenny" %in% colnames(times_summary)) {
254 times_summary %>% arrange(desc(`host lenny`)) -> times_summary
255 } else {
256 times_summary %>% arrange(desc(`host no-host`)) -> times_summary
257 }
258
259 Log('times_summary:')
260 print(times_summary)
261
262 # Summarize cachegrind by platform/shell
263 # Bug fix: as.numeric(irefs) avoids 32-bit integer overflow!
264 joined_cachegrind %>%
265 group_by(shell_label) %>%
266 summarize(total_lines = sum(num_lines), total_irefs = sum(as.numeric(irefs))) %>%
267 mutate(thousand_irefs_per_line = total_irefs / total_lines / 1000) %>%
268 select(-c(total_irefs)) ->
269 cachegrind_summary
270
271 if ("no-host" %in% distinct_hosts$host_label) {
272
273 # We don't have all the shells
274 elapsed = NULL
275 rate = NULL
276 max_rss = NULL
277 instructions = NULL
278
279 joined_times %>%
280 select(c(shell_label, elapsed_ms, user_ms, sys_ms, max_rss_MB,
281 num_lines, filename, filename_HREF)) %>%
282 arrange(filename, elapsed_ms) ->
283 times_flat
284
285 joined_cachegrind %>%
286 select(c(shell_label, irefs, num_lines, filename, filename_HREF)) %>%
287 arrange(filename, irefs) ->
288 cachegrind_flat
289
290 } else {
291
292 times_flat = NULL
293 cachegrind_flat = NULL
294
295 # Elapsed seconds for each shell by platform and file
296 joined_times %>%
297 select(-c(lines_per_ms, user_ms, sys_ms, max_rss_MB)) %>%
298 spread(key = shell_label, value = elapsed_ms) %>%
299 arrange(host_label, num_lines) %>%
300 mutate(osh_to_bash_ratio = `osh-native` / bash) %>%
301 select(c(host_label, bash, dash, mksh, zsh,
302 `osh-ovm`, `osh-cpython`, `osh-native`,
303 osh_to_bash_ratio, num_lines, filename, filename_HREF)) ->
304 elapsed
305
306 Log('\n')
307 Log('ELAPSED')
308 print(elapsed)
309
310 # Rates by file and shell
311 joined_times %>%
312 select(-c(elapsed_ms, user_ms, sys_ms, max_rss_MB)) %>%
313 spread(key = shell_label, value = lines_per_ms) %>%
314 arrange(host_label, num_lines) %>%
315 select(c(host_label, bash, dash, mksh, zsh,
316 `osh-ovm`, `osh-cpython`, `osh-native`,
317 num_lines, filename, filename_HREF)) ->
318 rate
319
320 Log('\n')
321 Log('RATE')
322 print(rate)
323
324 # Memory usage by file
325 joined_times %>%
326 select(-c(elapsed_ms, lines_per_ms, user_ms, sys_ms)) %>%
327 spread(key = shell_label, value = max_rss_MB) %>%
328 arrange(host_label, num_lines) %>%
329 select(c(host_label, bash, dash, mksh, zsh,
330 `osh-ovm`, `osh-cpython`, `osh-native`,
331 num_lines, filename, filename_HREF)) ->
332 max_rss
333
334 Log('\n')
335 Log('MAX RSS')
336 print(max_rss)
337
338 Log('\n')
339 Log('joined_cachegrind has %d rows', nrow(joined_cachegrind))
340 print(joined_cachegrind)
341 #print(joined_cachegrind %>% filter(path == 'benchmarks/testdata/configure-helper.sh'))
342
343 # Cachegrind instructions by file
344 joined_cachegrind %>%
345 mutate(thousand_irefs_per_line = irefs / num_lines / 1000) %>%
346 select(-c(irefs)) %>%
347 spread(key = shell_label, value = thousand_irefs_per_line) %>%
348 arrange(num_lines) %>%
349 select(c(bash, dash, mksh, `osh-native`,
350 num_lines, filename, filename_HREF)) ->
351 instructions
352
353 Log('\n')
354 Log('instructions has %d rows', nrow(instructions))
355 print(instructions)
356 }
357
358 WriteProvenance(distinct_hosts, distinct_shells, out_dir)
359
360 raw_data_table = tibble(
361 filename = basename(as.character(raw_data$path)),
362 filename_HREF = benchmarkDataLink('osh-parser', filename, '')
363 )
364 #print(raw_data_table)
365
366 writeCsv(raw_data_table, file.path(out_dir, 'raw-data'))
367
368 precision = SamePrecision(0) # lines per ms
369 writeCsv(times_summary, file.path(out_dir, 'summary'), precision)
370
371 precision = ColumnPrecision(list(), default = 1)
372 writeTsv(cachegrind_summary, file.path(out_dir, 'cachegrind_summary'), precision)
373
374 if (!is.null(times_flat)) {
375 precision = SamePrecision(0)
376 writeTsv(times_flat, file.path(out_dir, 'times_flat'), precision)
377 }
378
379 if (!is.null(cachegrind_flat)) {
380 precision = SamePrecision(0)
381 writeTsv(cachegrind_flat, file.path(out_dir, 'cachegrind_flat'), precision)
382 }
383
384 if (!is.null(elapsed)) { # equivalent to no-host
385 # Round to nearest millisecond, but the ratio has a decimal point.
386 precision = ColumnPrecision(list(osh_to_bash_ratio = 1), default = 0)
387 writeCsv(elapsed, file.path(out_dir, 'elapsed'), precision)
388
389 precision = SamePrecision(0)
390 writeCsv(rate, file.path(out_dir, 'rate'), precision)
391
392 writeCsv(max_rss, file.path(out_dir, 'max_rss'))
393
394 precision = SamePrecision(1)
395 writeTsv(instructions, file.path(out_dir, 'instructions'), precision)
396 }
397
398 Log('Wrote %s', out_dir)
399}
400
401WriteProvenance = function(distinct_hosts, distinct_shells, out_dir, tsv = F) {
402
403 num_hosts = nrow(distinct_hosts)
404 if (num_hosts == 1) {
405 linkify = provenanceLink
406 } else {
407 linkify = benchmarkDataLink
408 }
409
410 Log('distinct_hosts')
411 print(distinct_hosts)
412 Log('')
413
414 Log('distinct_shells')
415 print(distinct_shells)
416 Log('')
417
418 # Should be:
419 # host_id_url
420 # And then csv_to_html will be smart enough? It should take --url flag?
421 host_table = tibble(
422 host_label = distinct_hosts$host_label,
423 host_id = paste(distinct_hosts$host_name,
424 distinct_hosts$host_hash, sep='-'),
425 host_id_HREF = linkify('host-id', host_id, '/')
426 )
427 Log('host_table')
428 print(host_table)
429 Log('')
430
431 shell_table = tibble(
432 shell_label = distinct_shells$shell_label,
433 shell_id = paste(distinct_shells$shell_name,
434 distinct_shells$shell_hash, sep='-'),
435 shell_id_HREF = linkify('shell-id', shell_id, '/')
436 )
437
438 Log('shell_table')
439 print(shell_table)
440 Log('')
441
442 if (tsv) {
443 writeTsv(host_table, file.path(out_dir, 'hosts'))
444 writeTsv(shell_table, file.path(out_dir, 'shells'))
445 } else {
446 writeCsv(host_table, file.path(out_dir, 'hosts'))
447 writeCsv(shell_table, file.path(out_dir, 'shells'))
448 }
449}
450
451WriteSimpleProvenance = function(provenance, out_dir) {
452 Log('provenance')
453 print(provenance)
454 Log('')
455
456 # Legacy: add $shell_name, because "$shell_basename-$shell_hash" is what
457 # benchmarks/id.sh publish-shell-id uses
458 provenance %>%
459 mutate(shell_name = basename(sh_path)) %>%
460 distinct(shell_label, shell_name, shell_hash) ->
461 distinct_shells
462
463 Log('distinct_shells')
464 print(distinct_shells)
465 Log('')
466
467 provenance %>% distinct(host_label, host_name, host_hash) -> distinct_hosts
468
469 WriteProvenance(distinct_hosts, distinct_shells, out_dir, tsv = T)
470}
471
472RuntimeReport = function(in_dir, out_dir) {
473 times = readTsv(file.path(in_dir, 'times.tsv'))
474
475 gc_stats = readTsv(file.path(in_dir, 'gc_stats.tsv'))
476 provenance = readTsv(file.path(in_dir, 'provenance.tsv'))
477
478 times %>% filter(status != 0) -> failed
479 if (nrow(failed) != 0) {
480 print(failed)
481 stop('Some osh-runtime tasks failed')
482 }
483
484 # Joins:
485 # times <= sh_path => provenance
486 # times <= join_id, host_name => gc_stats
487
488 # TODO: provenance may have rows from 2 machines. Could validate them and
489 # deduplicate.
490
491 # It should have (host_label, host_name, host_hash)
492 # (shell_label, sh_path, shell_hash)
493 provenance %>%
494 mutate(host_label = host_name, shell_label = ShellLabelFromPath(sh_path)) ->
495 provenance
496
497 provenance %>% distinct(sh_path, shell_label) -> label_lookup
498
499 Log('label_lookup')
500 print(label_lookup)
501
502 # Join with provenance for host label and shell label
503 times %>%
504 select(c(elapsed_secs, user_secs, sys_secs, max_rss_KiB, task_id, host_name, sh_path, workload)) %>%
505 mutate(elapsed_ms = elapsed_secs * 1000,
506 user_ms = user_secs * 1000,
507 sys_ms = sys_secs * 1000,
508 max_rss_MB = max_rss_KiB * 1024 / 1e6) %>%
509 select(-c(elapsed_secs, user_secs, sys_secs, max_rss_KiB)) %>%
510 left_join(label_lookup, by = c('sh_path')) %>%
511 select(-c(sh_path)) ->
512 details
513
514 times %>%
515 select(c(task_id, host_name, sh_path, workload, minor_faults, major_faults, swaps, in_block, out_block, signals, voluntary_ctx, involuntary_ctx)) %>%
516 left_join(label_lookup, by = c('sh_path')) %>%
517 select(-c(sh_path)) ->
518 details_io
519
520 Log('details')
521 print(details)
522
523 # Elapsed time comparison
524 details %>%
525 select(-c(task_id, user_ms, sys_ms, max_rss_MB)) %>%
526 spread(key = shell_label, value = elapsed_ms) %>%
527 mutate(py_bash_ratio = `osh-cpython` / bash) %>%
528 mutate(native_bash_ratio = `osh-native` / bash) %>%
529 arrange(workload, host_name) %>%
530 select(c(workload, host_name,
531 bash, dash, `osh-cpython`, `osh-native`,
532 py_bash_ratio, native_bash_ratio)) ->
533
534 elapsed
535
536 Log('elapsed')
537 print(elapsed)
538
539 # Minor Page Faults Comparison
540 details_io %>%
541 select(c(host_name, shell_label, workload, minor_faults)) %>%
542 spread(key = shell_label, value = minor_faults) %>%
543 mutate(py_bash_ratio = `osh-cpython` / bash) %>%
544 mutate(native_bash_ratio = `osh-native` / bash) %>%
545 arrange(workload, host_name) %>%
546 select(c(workload, host_name,
547 bash, dash, `osh-cpython`, `osh-native`,
548 py_bash_ratio, native_bash_ratio)) ->
549 page_faults
550
551 Log('page_faults')
552 print(page_faults)
553
554 # Max RSS comparison
555 details %>%
556 select(-c(task_id, elapsed_ms, user_ms, sys_ms)) %>%
557 spread(key = shell_label, value = max_rss_MB) %>%
558 mutate(py_bash_ratio = `osh-cpython` / bash) %>%
559 mutate(native_bash_ratio = `osh-native` / bash) %>%
560 arrange(workload, host_name) %>%
561 select(c(workload, host_name,
562 bash, dash, `osh-cpython`, `osh-native`,
563 py_bash_ratio, native_bash_ratio)) ->
564 max_rss
565
566 Log('max rss')
567 print(max_rss)
568
569 details %>%
570 select(c(task_id, host_name, workload, elapsed_ms, max_rss_MB)) %>%
571 mutate(join_id = sprintf("gc-%d", task_id)) %>%
572 select(-c(task_id)) ->
573 gc_details
574
575 Log('GC stats')
576 print(gc_stats)
577
578 gc_stats %>%
579 left_join(gc_details, by = c('join_id', 'host_name')) %>%
580 select(-c(join_id, roots_capacity, objs_capacity)) %>%
581 # Do same transformations as GcReport()
582 mutate(allocated_MB = bytes_allocated / 1e6) %>%
583 select(-c(bytes_allocated)) %>%
584 rename(num_gc_done = num_collections) %>%
585 # Put these columns first
586 relocate(workload, host_name,
587 elapsed_ms, max_gc_millis, total_gc_millis,
588 allocated_MB, max_rss_MB, num_allocated) ->
589 gc_stats
590
591 Log('After GC stats')
592 print(gc_stats)
593
594 WriteSimpleProvenance(provenance, out_dir)
595
596 # milliseconds don't need decimal digit
597 precision = ColumnPrecision(list(bash = 0, dash = 0, `osh-cpython` = 0,
598 `osh-native` = 0, py_bash_ratio = 2,
599 native_bash_ratio = 2))
600 writeTsv(elapsed, file.path(out_dir, 'elapsed'), precision)
601 writeTsv(page_faults, file.path(out_dir, 'page_faults'), precision)
602
603 precision2 = ColumnPrecision(list(py_bash_ratio = 2, native_bash_ratio = 2))
604 writeTsv(max_rss, file.path(out_dir, 'max_rss'), precision2)
605
606 precision3 = ColumnPrecision(list(max_rss_MB = 1, allocated_MB = 1),
607 default = 0)
608 writeTsv(gc_stats, file.path(out_dir, 'gc_stats'), precision3)
609 writeTsv(details, file.path(out_dir, 'details'), precision3)
610 writeTsv(details_io, file.path(out_dir, 'details_io'))
611
612 Log('Wrote %s', out_dir)
613}
614
615VmBaselineReport = function(in_dir, out_dir) {
616 vm = read.csv(file.path(in_dir, 'vm-baseline.csv'))
617 #print(vm)
618
619 # Not using DistinctHosts() because field host_hash isn't collected
620 num_hosts = nrow(vm %>% distinct(host))
621
622 vm %>%
623 rename(kib = metric_value) %>%
624 mutate(shell_label = ShellLabels(shell_name, shell_hash, num_hosts),
625 megabytes = kib * 1024 / 1e6) %>%
626 select(-c(shell_name, kib)) %>%
627 spread(key = c(metric_name), value = megabytes) %>%
628 rename(VmPeak_MB = VmPeak, VmRSS_MB = VmRSS) %>%
629 select(c(shell_label, shell_hash, host, VmRSS_MB, VmPeak_MB)) %>%
630 arrange(shell_label, shell_hash, host, VmPeak_MB) ->
631 vm
632
633 print(vm)
634
635 writeCsv(vm, file.path(out_dir, 'vm-baseline'))
636}
637
638WriteOvmBuildDetails = function(distinct_hosts, distinct_compilers, out_dir) {
639 host_table = tibble(
640 host_label = distinct_hosts$host_label,
641 host_id = paste(distinct_hosts$host_name,
642 distinct_hosts$host_hash, sep='-'),
643 host_id_HREF = benchmarkDataLink('host-id', host_id, '/')
644 )
645 print(host_table)
646
647 dc = distinct_compilers
648 compiler_table = tibble(
649 compiler_label = dc$compiler_label,
650 compiler_id = paste(dc$compiler_label, dc$compiler_hash, sep='-'),
651 compiler_id_HREF = benchmarkDataLink('compiler-id', compiler_id, '/')
652 )
653 print(compiler_table)
654
655 writeTsv(host_table, file.path(out_dir, 'hosts'))
656 writeTsv(compiler_table, file.path(out_dir, 'compilers'))
657}
658
659OvmBuildReport = function(in_dir, out_dir) {
660 times = readTsv(file.path(in_dir, 'times.tsv'))
661 bytecode_size = readTsv(file.path(in_dir, 'bytecode-size.tsv'))
662 bin_sizes = readTsv(file.path(in_dir, 'bin-sizes.tsv'))
663 native_sizes = readTsv(file.path(in_dir, 'native-sizes.tsv'))
664 raw_data = readTsv(file.path(in_dir, 'raw-data.tsv'))
665
666 times %>% filter(status != 0) -> failed
667 if (nrow(failed) != 0) {
668 print(failed)
669 stop('Some ovm-build tasks failed')
670 }
671
672 times %>% distinct(host_name, host_hash) -> distinct_hosts
673 distinct_hosts$host_label = distinct_hosts$host_name
674
675 times %>% distinct(compiler_path, compiler_hash) -> distinct_compilers
676 distinct_compilers$compiler_label = basename(distinct_compilers$compiler_path)
677
678 #print(distinct_hosts)
679 #print(distinct_compilers)
680
681 WriteOvmBuildDetails(distinct_hosts, distinct_compilers, out_dir)
682
683 times %>%
684 select(-c(status)) %>%
685 left_join(distinct_hosts, by = c('host_name', 'host_hash')) %>%
686 left_join(distinct_compilers, by = c('compiler_path', 'compiler_hash')) %>%
687 select(-c(host_name, host_hash, compiler_path, compiler_hash)) %>%
688 mutate(src_dir = basename(src_dir),
689 host_label = paste("host ", host_label),
690 is_conf = str_detect(action, 'configure'),
691 is_ovm = str_detect(action, 'oil.ovm'),
692 is_dbg = str_detect(action, 'dbg'),
693 ) %>%
694 select(host_label, src_dir, compiler_label, action, is_conf, is_ovm, is_dbg,
695 elapsed_secs) %>%
696 spread(key = c(host_label), value = elapsed_secs) %>%
697 arrange(src_dir, compiler_label, desc(is_conf), is_ovm, desc(is_dbg)) %>%
698 select(-c(is_conf, is_ovm, is_dbg)) ->
699 times
700
701 #print(times)
702
703 bytecode_size %>%
704 rename(bytecode_size = num_bytes) %>%
705 select(-c(path)) ->
706 bytecode_size
707
708 bin_sizes %>%
709 # reorder
710 select(c(host_label, path, num_bytes)) %>%
711 left_join(bytecode_size, by = c('host_label')) %>%
712 mutate(native_code_size = num_bytes - bytecode_size) ->
713 sizes
714
715 # paths look like _tmp/ovm-build/bin/clang/oils_cpp.stripped
716 native_sizes %>%
717 select(c(host_label, path, num_bytes)) %>%
718 mutate(host_label = paste("host ", host_label),
719 binary = basename(path),
720 compiler = basename(dirname(path)),
721 ) %>%
722 select(-c(path)) %>%
723 spread(key = c(host_label), value = num_bytes) %>%
724 arrange(compiler, binary) ->
725 native_sizes
726
727 # NOTE: These don't have the host and compiler.
728 writeTsv(times, file.path(out_dir, 'times'))
729 writeTsv(bytecode_size, file.path(out_dir, 'bytecode-size'))
730 writeTsv(sizes, file.path(out_dir, 'sizes'))
731 writeTsv(native_sizes, file.path(out_dir, 'native-sizes'))
732
733 # TODO: I want a size report too
734 #writeCsv(sizes, file.path(out_dir, 'sizes'))
735}
736
737unique_stdout_md5sum = function(t, num_expected) {
738 u = n_distinct(t$stdout_md5sum)
739 if (u != num_expected) {
740 t %>% select(c(host_name, task_name, arg1, arg2, runtime_name, stdout_md5sum)) %>% print()
741 stop(sprintf('Expected %d unique md5sums, got %d', num_expected, u))
742 }
743}
744
745ComputeReport = function(in_dir, out_dir) {
746 # TSV file, not CSV
747 times = read.table(file.path(in_dir, 'times.tsv'), header=T)
748 print(times)
749
750 times %>% filter(status != 0) -> failed
751 if (nrow(failed) != 0) {
752 print(failed)
753 stop('Some compute tasks failed')
754 }
755
756 #
757 # Check correctness
758 #
759
760 times %>% filter(task_name == 'hello') %>% unique_stdout_md5sum(1)
761 times %>% filter(task_name == 'fib') %>% unique_stdout_md5sum(1)
762 times %>% filter(task_name == 'word_freq') %>% unique_stdout_md5sum(1)
763 # 3 different inputs
764 times %>% filter(task_name == 'parse_help') %>% unique_stdout_md5sum(3)
765
766 times %>% filter(task_name == 'bubble_sort') %>% unique_stdout_md5sum(2)
767
768 # TODO:
769 # - oils_cpp doesn't implement unicode LANG=C
770 # - bash behaves differently on your desktop vs. in the container
771 # - might need layer-locales in the image?
772
773 #times %>% filter(task_name == 'palindrome' & arg1 == 'unicode') %>% unique_stdout_md5sum(1)
774 # Ditto here
775 #times %>% filter(task_name == 'palindrome' & arg1 == 'bytes') %>% unique_stdout_md5sum(1)
776
777 #
778 # Find distinct shells and hosts, and label them for readability.
779 #
780
781 # Runtimes are called shells, as a hack for code reuse
782 times %>%
783 mutate(shell_name = runtime_name, shell_hash = runtime_hash) %>%
784 select(c(host_name, host_hash, shell_name, shell_hash)) ->
785 tmp
786
787 distinct_hosts = DistinctHosts(tmp)
788 Log('')
789 Log('Distinct hosts')
790 print(distinct_hosts)
791
792 distinct_shells = DistinctShells(tmp)
793 Log('')
794 Log('Distinct runtimes')
795 print(distinct_shells)
796
797 num_hosts = nrow(distinct_hosts)
798
799 times %>%
800 select(-c(status, stdout_md5sum, stdout_filename, host_hash, runtime_hash)) %>%
801 mutate(runtime_label = ShellLabels(runtime_name, runtime_hash, num_hosts),
802 elapsed_ms = elapsed_secs * 1000,
803 user_ms = user_secs * 1000,
804 sys_ms = sys_secs * 1000,
805 max_rss_MB = max_rss_KiB * 1024 / 1e6) %>%
806 select(-c(runtime_name, elapsed_secs, user_secs, sys_secs, max_rss_KiB)) %>%
807 arrange(host_name, task_name, arg1, arg2, user_ms) ->
808 details
809
810 times %>%
811 mutate(
812 runtime_label = ShellLabels(runtime_name, runtime_hash, num_hosts),
813 stdout_md5sum_HREF = file.path('tmp', task_name, stdout_filename)) %>%
814 select(c(host_name, task_name, arg1, arg2, runtime_label,
815 stdout_md5sum, stdout_md5sum_HREF)) ->
816 stdout_files
817
818 details %>% filter(task_name == 'hello') %>% select(-c(task_name)) -> hello
819 details %>% filter(task_name == 'fib') %>% select(-c(task_name)) -> fib
820 details %>% filter(task_name == 'word_freq') %>% select(-c(task_name)) -> word_freq
821 # There's no arg2
822 details %>% filter(task_name == 'parse_help') %>% select(-c(task_name, arg2)) -> parse_help
823
824 details %>% filter(task_name == 'bubble_sort') %>% select(-c(task_name)) -> bubble_sort
825 details %>% filter(task_name == 'palindrome' & arg1 == 'unicode') %>% select(-c(task_name)) -> palindrome
826
827 precision = ColumnPrecision(list(max_rss_MB = 1), default = 0)
828 writeTsv(details, file.path(out_dir, 'details'), precision)
829
830 writeTsv(stdout_files, file.path(out_dir, 'stdout_files'), precision)
831
832 writeTsv(hello, file.path(out_dir, 'hello'), precision)
833 writeTsv(fib, file.path(out_dir, 'fib'), precision)
834 writeTsv(word_freq, file.path(out_dir, 'word_freq'), precision)
835 writeTsv(parse_help, file.path(out_dir, 'parse_help'), precision)
836
837 writeTsv(bubble_sort, file.path(out_dir, 'bubble_sort'), precision)
838 writeTsv(palindrome, file.path(out_dir, 'palindrome'), precision)
839
840 WriteProvenance(distinct_hosts, distinct_shells, out_dir, tsv = T)
841}
842
843WriteOneTask = function(times, out_dir, task_name, precision) {
844 times %>%
845 filter(task == task_name) %>%
846 select(-c(task)) -> subset
847
848 writeTsv(subset, file.path(out_dir, task_name), precision)
849}
850
851SHELL_ORDER = c('dash',
852 'bash',
853 'zsh',
854 '_bin/cxx-opt+bumpleak/osh',
855 '_bin/cxx-opt+bumproot/osh',
856 '_bin/cxx-opt+bumpsmall/osh',
857 '_bin/cxx-opt/osh',
858 '_bin/cxx-opt+nopool/osh')
859
860GcReport = function(in_dir, out_dir) {
861 times = read.table(file.path(in_dir, 'raw/times.tsv'), header=T)
862 gc_stats = read.table(file.path(in_dir, 'stage1/gc_stats.tsv'), header=T)
863
864 times %>% filter(status != 0) -> failed
865 if (nrow(failed) != 0) {
866 print(failed)
867 stop('Some gc tasks failed')
868 }
869
870 # Change units and order columns
871 times %>%
872 arrange(task, factor(sh_path, levels = SHELL_ORDER)) %>%
873 mutate(elapsed_ms = elapsed_secs * 1000,
874 user_ms = user_secs * 1000,
875 sys_ms = sys_secs * 1000,
876 max_rss_MB = max_rss_KiB * 1024 / 1e6,
877 shell_label = ShellLabelFromPath(sh_path)
878 ) %>%
879 select(c(join_id, task, elapsed_ms, user_ms, sys_ms, max_rss_MB, shell_label,
880 shell_runtime_opts)) ->
881 times
882
883 # Join and order columns
884 gc_stats %>% left_join(times, by = c('join_id')) %>%
885 arrange(desc(task)) %>%
886 mutate(allocated_MB = bytes_allocated / 1e6) %>%
887 # try to make the table skinnier
888 rename(num_gc_done = num_collections) %>%
889 select(task, elapsed_ms, max_gc_millis, total_gc_millis,
890 allocated_MB, max_rss_MB, num_allocated,
891 num_gc_points, num_gc_done, gc_threshold, num_growths, max_survived,
892 shell_label) ->
893 gc_stats
894
895 times %>% select(-c(join_id)) -> times
896
897
898 precision = ColumnPrecision(list(max_rss_MB = 1, allocated_MB = 1),
899 default = 0)
900
901 writeTsv(times, file.path(out_dir, 'times'), precision)
902 writeTsv(gc_stats, file.path(out_dir, 'gc_stats'), precision)
903
904 tasks = c('parse.configure-coreutils',
905 'parse.configure-cpython',
906 'parse.abuild',
907 'ex.compute-fib',
908 'ex.bashcomp-parse-help',
909 'ex.abuild-print-help')
910 # Write out separate rows
911 for (task in tasks) {
912 WriteOneTask(times, out_dir, task, precision)
913 }
914}
915
916GcCachegrindReport = function(in_dir, out_dir) {
917 times = readTsv(file.path(in_dir, 'raw/times.tsv'))
918 counts = readTsv(file.path(in_dir, 'stage1/cachegrind.tsv'))
919
920 times %>% filter(status != 0) -> failed
921 if (nrow(failed) != 0) {
922 print(failed)
923 stop('Some gc tasks failed')
924 }
925
926 print(times)
927 print(counts)
928
929 counts %>% left_join(times, by = c('join_id')) %>%
930 mutate(million_irefs = irefs / 1e6) %>%
931 select(c(million_irefs, task, sh_path, shell_runtime_opts)) %>%
932 arrange(factor(sh_path, levels = SHELL_ORDER)) ->
933 counts
934
935 precision = NULL
936 tasks = c('parse.abuild', 'ex.compute-fib')
937 for (task in tasks) {
938 WriteOneTask(counts, out_dir, task, precision)
939 }
940}
941
942MyCppReport = function(in_dir, out_dir) {
943 times = readTsv(file.path(in_dir, 'benchmark-table.tsv'))
944 print(times)
945
946 times %>% filter(status != 0) -> failed
947 if (nrow(failed) != 0) {
948 print(failed)
949 stop('Some mycpp tasks failed')
950 }
951
952 # Don't care about elapsed and system
953 times %>% select(-c(status, elapsed_secs, bin, task_out)) %>%
954 mutate(example_name_HREF = mycppUrl(example_name),
955 user_ms = user_secs * 1000,
956 sys_ms = sys_secs * 1000,
957 max_rss_MB = max_rss_KiB * 1024 / 1e6) %>%
958 select(-c(user_secs, sys_secs, max_rss_KiB)) ->
959 details
960
961 details %>% select(-c(sys_ms, max_rss_MB)) %>%
962 spread(key = impl, value = user_ms) %>%
963 mutate(`C++ : Python` = `C++` / Python) %>%
964 arrange(`C++ : Python`) ->
965 user_time
966
967 details %>% select(-c(user_ms, max_rss_MB)) %>%
968 spread(key = impl, value = sys_ms) %>%
969 mutate(`C++ : Python` = `C++` / Python) %>%
970 arrange(`C++ : Python`) ->
971 sys_time
972
973 details %>% select(-c(user_ms, sys_ms)) %>%
974 spread(key = impl, value = max_rss_MB) %>%
975 mutate(`C++ : Python` = `C++` / Python) %>%
976 arrange(`C++ : Python`) ->
977 max_rss
978
979 # Sometimes it speeds up by more than 10x
980 precision1 = ColumnPrecision(list(`C++ : Python` = 3), default = 0)
981 writeTsv(user_time, file.path(out_dir, 'user_time'), precision1)
982 writeTsv(sys_time, file.path(out_dir, 'sys_time'), precision1)
983
984 precision2 = ColumnPrecision(list(`C++ : Python` = 2), default = 1)
985 writeTsv(max_rss, file.path(out_dir, 'max_rss'), precision2)
986
987 writeTsv(details, file.path(out_dir, 'details'))
988}
989
990UftraceTaskReport = function(env, task_name, summaries) {
991 # Need this again after redirect
992 MaybeDisableColor(stdout())
993
994 task_env = env[[task_name]]
995
996 untyped = task_env$untyped
997 typed = task_env$typed
998 strings = task_env$strings
999 slabs = task_env$slabs
1000 reserve = task_env$reserve
1001
1002 string_overhead = 17 # GC header (8) + len (4) + hash value (4) + NUL (1)
1003 strings %>% mutate(obj_len = str_len + string_overhead) -> strings
1004
1005 # TODO: Output these totals PER WORKLOAD, e.g. parsing big/small, executing
1006 # big/small
1007 #
1008 # And then zoom in on distributions as well
1009
1010 num_allocs = nrow(untyped)
1011 total_bytes = sum(untyped$obj_len)
1012
1013 untyped %>% group_by(obj_len) %>% count() %>% ungroup() -> untyped_hist
1014 #print(untyped_hist)
1015
1016 untyped_hist %>%
1017 mutate(n_less_than = cumsum(n),
1018 percent = n_less_than * 100.0 / num_allocs) ->
1019 alloc_sizes
1020
1021 a24 = untyped_hist %>% filter(obj_len <= 24)
1022 a48 = untyped_hist %>% filter(obj_len <= 48)
1023 a96 = untyped_hist %>% filter(obj_len <= 96)
1024
1025 allocs_24_bytes_or_less = sum(a24$n) * 100.0 / num_allocs
1026 allocs_48_bytes_or_less = sum(a48$n) * 100.0 / num_allocs
1027 allocs_96_bytes_or_less = sum(a96$n) * 100.0 / num_allocs
1028
1029 Log('Percentage of allocs less than 48 bytes: %.1f', allocs_48_bytes_or_less)
1030
1031 options(tibble.print_min=25)
1032
1033 Log('')
1034 Log('All allocations')
1035 print(alloc_sizes %>% head(22))
1036 print(alloc_sizes %>% tail(5))
1037
1038 Log('')
1039 Log('Common Sizes')
1040 print(untyped_hist %>% arrange(desc(n)) %>% head(8))
1041
1042 Log('')
1043 Log(' %s total allocations, total bytes = %s', commas(num_allocs), commas(total_bytes))
1044 Log('')
1045
1046 Log('Typed allocations')
1047
1048 num_typed = nrow(typed)
1049
1050 typed %>% group_by(func_name) %>% count() %>% ungroup() %>%
1051 mutate(percent = n * 100.0 / num_typed) %>%
1052 arrange(desc(n)) -> most_common_types
1053
1054 print(most_common_types %>% head(20))
1055 print(most_common_types %>% tail(5))
1056
1057 lists = typed %>% filter(str_starts(func_name, ('List<')))
1058 #print(lists)
1059
1060 num_lists = nrow(lists)
1061 total_list_bytes = num_lists * 24 # sizeof List<T> head is hard-coded
1062
1063 Log('')
1064 Log('%s typed allocs, including %s List<T>', commas(num_typed), commas(num_lists))
1065 Log('%.2f%% of allocs are typed', num_typed * 100 / num_allocs)
1066 Log('')
1067
1068 #
1069 # Strings
1070 #
1071
1072 num_strings = nrow(strings)
1073 total_string_bytes = sum(strings$obj_len)
1074
1075 strings %>% group_by(str_len) %>% count() %>% ungroup() %>%
1076 mutate(n_less_than = cumsum(n),
1077 percent = n_less_than * 100.0 / num_strings) ->
1078 string_lengths
1079
1080 strs_6_bytes_or_less = string_lengths %>% filter(str_len == 6) %>% select(percent)
1081 strs_14_bytes_or_less = string_lengths %>% filter(str_len == 14) %>% select(percent)
1082
1083 # Parse workload
1084 # 62% of strings <= 6 bytes
1085 # 84% of strings <= 14 bytes
1086
1087 Log('Str - NewStr() and OverAllocatedStr()')
1088 print(string_lengths %>% head(16))
1089 print(string_lengths %>% tail(5))
1090 Log('')
1091
1092 Log('%s string allocations, total length = %s, total bytes = %s', commas(num_strings),
1093 commas(sum(strings$str_len)), commas(total_string_bytes))
1094 Log('')
1095 Log('%.2f%% of allocs are strings', num_strings * 100 / num_allocs)
1096 Log('%.2f%% of bytes are strings', total_string_bytes * 100 / total_bytes)
1097 Log('')
1098
1099 #
1100 # Slabs
1101 #
1102
1103 Log('NewSlab()')
1104
1105 num_slabs = nrow(slabs)
1106 slabs %>% group_by(slab_len) %>% count() %>% ungroup() %>%
1107 mutate(n_less_than = cumsum(n),
1108 percent = n_less_than * 100.0 / num_slabs) ->
1109 slab_lengths
1110
1111 slabs %>% group_by(func_name) %>% count() %>% ungroup() %>%
1112 arrange(desc(n)) -> slab_types
1113
1114 Log(' Lengths')
1115 print(slab_lengths %>% head())
1116 print(slab_lengths %>% tail(5))
1117 Log('')
1118
1119 Log(' Slab Types')
1120 print(slab_types %>% head())
1121 print(slab_types %>% tail(5))
1122 Log('')
1123
1124 total_slab_items = sum(slabs$slab_len)
1125
1126 Log('%s slabs, total items = %s', commas(num_slabs),
1127 commas(sum(slabs$slab_len)))
1128 Log('%.2f%% of allocs are slabs', num_slabs * 100 / num_allocs)
1129 Log('')
1130
1131 #
1132 # reserve() calls
1133 #
1134
1135 # There should be strictly more List::reserve() calls than NewSlab
1136
1137 Log('::reserve(int n)')
1138 Log('')
1139
1140 num_reserve = nrow(reserve)
1141 reserve %>% group_by(num_items) %>% count() %>% ungroup() %>%
1142 mutate(n_less_than = cumsum(n),
1143 percent = n_less_than * 100.0 / num_reserve) ->
1144 reserve_args
1145
1146 Log(' Num Items')
1147 print(reserve_args %>% head(15))
1148 print(reserve_args %>% tail(5))
1149 Log('')
1150
1151 Log('%s reserve() calls, total items = %s', commas(num_reserve),
1152 commas(sum(reserve$num_items)))
1153 Log('')
1154
1155 # Accounting for all allocations!
1156 Log('Untyped: %s', commas(num_allocs))
1157 Log('Typed + Str + Slab: %s', commas(num_typed + num_strings + num_slabs))
1158 Log('')
1159
1160 num_other_typed = num_typed - num_lists
1161
1162 # Summary table
1163 stats = tibble(task = task_name,
1164 total_bytes_ = commas(total_bytes),
1165 num_allocs_ = commas(num_allocs),
1166 sum_typed_strs_slabs = commas(num_typed + num_strings + num_slabs),
1167 num_reserve_calls = commas(num_reserve),
1168
1169 percent_list_allocs = Percent(num_lists, num_allocs),
1170 percent_slab_allocs = Percent(num_slabs, num_allocs),
1171 percent_string_allocs = Percent(num_strings, num_allocs),
1172 percent_other_typed_allocs = Percent(num_other_typed, num_allocs),
1173
1174 percent_list_bytes = Percent(total_list_bytes, total_bytes),
1175 percent_string_bytes = Percent(total_string_bytes, total_bytes),
1176
1177 allocs_24_bytes_or_less = sprintf('%.1f%%', allocs_24_bytes_or_less),
1178 allocs_48_bytes_or_less = sprintf('%.1f%%', allocs_48_bytes_or_less),
1179 allocs_96_bytes_or_less = sprintf('%.1f%%', allocs_96_bytes_or_less),
1180
1181 strs_6_bytes_or_less = sprintf('%.1f%%', strs_6_bytes_or_less),
1182 strs_14_bytes_or_less = sprintf('%.1f%%', strs_14_bytes_or_less),
1183 )
1184 summaries$stats[[task_name]] = stats
1185
1186 summaries$most_common_types[[task_name]] = most_common_types
1187}
1188
1189LoadUftraceTsv = function(in_dir, env) {
1190 for (task in list.files(in_dir)) {
1191 Log('Loading data for task %s', task)
1192 base_dir = file.path(in_dir, task)
1193
1194 task_env = new.env()
1195 env[[task]] = task_env
1196
1197 # TSV file, not CSV
1198 task_env$untyped = readTsv(file.path(base_dir, 'all-untyped.tsv'))
1199 task_env$typed = readTsv(file.path(base_dir, 'typed.tsv'))
1200 task_env$strings = readTsv(file.path(base_dir, 'strings.tsv'))
1201 task_env$slabs = readTsv(file.path(base_dir, 'slabs.tsv'))
1202 task_env$reserve = readTsv(file.path(base_dir, 'reserve.tsv'))
1203
1204 # median string length is 4, mean is 9.5!
1205 Log('UNTYPED')
1206 print(summary(task_env$untyped))
1207 Log('')
1208
1209 Log('TYPED')
1210 print(summary(task_env$typed))
1211 Log('')
1212
1213 Log('STRINGS')
1214 print(summary(task_env$strings))
1215 Log('')
1216
1217 Log('SLABS')
1218 print(summary(task_env$slabs))
1219 Log('')
1220
1221 Log('RESERVE')
1222 print(summary(task_env$reserve))
1223 Log('')
1224 }
1225}
1226
1227Percent = function(n, total) {
1228 sprintf('%.1f%%', n * 100.0 / total)
1229}
1230
1231PrettyPrintLong = function(d) {
1232 tr = t(d) # transpose
1233
1234 row_names = rownames(tr)
1235
1236 for (i in 1:nrow(tr)) {
1237 row_name = row_names[i]
1238 cat(sprintf('%26s', row_name)) # calculated min width manually
1239 cat(sprintf('%20s', tr[i,]))
1240 cat('\n')
1241
1242 # Extra spacing
1243 if (row_name %in% c('num_reserve_calls',
1244 'percent_string_bytes',
1245 'percent_other_typed_allocs',
1246 'allocs_96_bytes_or_less')) {
1247 cat('\n')
1248 }
1249 }
1250}
1251
1252
1253UftraceReport = function(env, out_dir) {
1254 # summaries$stats should be a list of 1-row data frames
1255 # summaries$top_types should be a list of types
1256 summaries = new.env()
1257
1258 for (task_name in names(env)) {
1259 report_out = file.path(out_dir, paste0(task_name, '.txt'))
1260
1261 Log('Making report for task %s -> %s', task_name, report_out)
1262
1263 sink(file = report_out)
1264 UftraceTaskReport(env, task_name, summaries)
1265 sink() # reset
1266 }
1267 Log('')
1268
1269 # Concate all the data frames added to summary
1270 stats = bind_rows(as.list(summaries$stats))
1271
1272 sink(file = file.path(out_dir, 'summary.txt'))
1273 #print(stats)
1274 #Log('')
1275
1276 PrettyPrintLong(stats)
1277 Log('')
1278
1279 mct = summaries$most_common_types
1280 for (task_name in names(mct)) {
1281 Log('Common types in workload %s', task_name)
1282 Log('')
1283
1284 print(mct[[task_name]] %>% head(5))
1285 Log('')
1286 }
1287 sink()
1288
1289 # For the REPL
1290 return(list(stats = stats))
1291}
1292
1293main = function(argv) {
1294 action = argv[[1]]
1295 in_dir = argv[[2]]
1296 out_dir = argv[[3]]
1297
1298 if (action == 'osh-parser') {
1299 ParserReport(in_dir, out_dir)
1300
1301 } else if (action == 'osh-runtime') {
1302 RuntimeReport(in_dir, out_dir)
1303
1304 } else if (action == 'vm-baseline') {
1305 VmBaselineReport(in_dir, out_dir)
1306
1307 } else if (action == 'ovm-build') {
1308 OvmBuildReport(in_dir, out_dir)
1309
1310 } else if (action == 'compute') {
1311 ComputeReport(in_dir, out_dir)
1312
1313 } else if (action == 'gc') {
1314 GcReport(in_dir, out_dir)
1315
1316 } else if (action == 'gc-cachegrind') {
1317 GcCachegrindReport(in_dir, out_dir)
1318
1319 } else if (action == 'mycpp') {
1320 MyCppReport(in_dir, out_dir)
1321
1322 } else if (action == 'uftrace') {
1323 d = new.env()
1324 LoadUftraceTsv(in_dir, d)
1325 UftraceReport(d, out_dir)
1326
1327 } else {
1328 Log("Invalid action '%s'", action)
1329 quit(status = 1)
1330 }
1331 Log('PID %d done', Sys.getpid())
1332}
1333
1334if (length(sys.frames()) == 0) {
1335 # increase ggplot font size globally
1336 #theme_set(theme_grey(base_size = 20))
1337
1338 main(commandArgs(TRUE))
1339}