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

1341 lines, 929 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
610 details %>% arrange(workload) -> details_sorted
611 writeTsv(details_sorted, file.path(out_dir, 'details'), precision3)
612 writeTsv(details_io, file.path(out_dir, 'details_io'))
613
614 Log('Wrote %s', out_dir)
615}
616
617VmBaselineReport = function(in_dir, out_dir) {
618 vm = read.csv(file.path(in_dir, 'vm-baseline.csv'))
619 #print(vm)
620
621 # Not using DistinctHosts() because field host_hash isn't collected
622 num_hosts = nrow(vm %>% distinct(host))
623
624 vm %>%
625 rename(kib = metric_value) %>%
626 mutate(shell_label = ShellLabels(shell_name, shell_hash, num_hosts),
627 megabytes = kib * 1024 / 1e6) %>%
628 select(-c(shell_name, kib)) %>%
629 spread(key = c(metric_name), value = megabytes) %>%
630 rename(VmPeak_MB = VmPeak, VmRSS_MB = VmRSS) %>%
631 select(c(shell_label, shell_hash, host, VmRSS_MB, VmPeak_MB)) %>%
632 arrange(shell_label, shell_hash, host, VmPeak_MB) ->
633 vm
634
635 print(vm)
636
637 writeCsv(vm, file.path(out_dir, 'vm-baseline'))
638}
639
640WriteOvmBuildDetails = function(distinct_hosts, distinct_compilers, out_dir) {
641 host_table = tibble(
642 host_label = distinct_hosts$host_label,
643 host_id = paste(distinct_hosts$host_name,
644 distinct_hosts$host_hash, sep='-'),
645 host_id_HREF = benchmarkDataLink('host-id', host_id, '/')
646 )
647 print(host_table)
648
649 dc = distinct_compilers
650 compiler_table = tibble(
651 compiler_label = dc$compiler_label,
652 compiler_id = paste(dc$compiler_label, dc$compiler_hash, sep='-'),
653 compiler_id_HREF = benchmarkDataLink('compiler-id', compiler_id, '/')
654 )
655 print(compiler_table)
656
657 writeTsv(host_table, file.path(out_dir, 'hosts'))
658 writeTsv(compiler_table, file.path(out_dir, 'compilers'))
659}
660
661OvmBuildReport = function(in_dir, out_dir) {
662 times = readTsv(file.path(in_dir, 'times.tsv'))
663 bytecode_size = readTsv(file.path(in_dir, 'bytecode-size.tsv'))
664 bin_sizes = readTsv(file.path(in_dir, 'bin-sizes.tsv'))
665 native_sizes = readTsv(file.path(in_dir, 'native-sizes.tsv'))
666 raw_data = readTsv(file.path(in_dir, 'raw-data.tsv'))
667
668 times %>% filter(status != 0) -> failed
669 if (nrow(failed) != 0) {
670 print(failed)
671 stop('Some ovm-build tasks failed')
672 }
673
674 times %>% distinct(host_name, host_hash) -> distinct_hosts
675 distinct_hosts$host_label = distinct_hosts$host_name
676
677 times %>% distinct(compiler_path, compiler_hash) -> distinct_compilers
678 distinct_compilers$compiler_label = basename(distinct_compilers$compiler_path)
679
680 #print(distinct_hosts)
681 #print(distinct_compilers)
682
683 WriteOvmBuildDetails(distinct_hosts, distinct_compilers, out_dir)
684
685 times %>%
686 select(-c(status)) %>%
687 left_join(distinct_hosts, by = c('host_name', 'host_hash')) %>%
688 left_join(distinct_compilers, by = c('compiler_path', 'compiler_hash')) %>%
689 select(-c(host_name, host_hash, compiler_path, compiler_hash)) %>%
690 mutate(src_dir = basename(src_dir),
691 host_label = paste("host ", host_label),
692 is_conf = str_detect(action, 'configure'),
693 is_ovm = str_detect(action, 'oil.ovm'),
694 is_dbg = str_detect(action, 'dbg'),
695 ) %>%
696 select(host_label, src_dir, compiler_label, action, is_conf, is_ovm, is_dbg,
697 elapsed_secs) %>%
698 spread(key = c(host_label), value = elapsed_secs) %>%
699 arrange(src_dir, compiler_label, desc(is_conf), is_ovm, desc(is_dbg)) %>%
700 select(-c(is_conf, is_ovm, is_dbg)) ->
701 times
702
703 #print(times)
704
705 bytecode_size %>%
706 rename(bytecode_size = num_bytes) %>%
707 select(-c(path)) ->
708 bytecode_size
709
710 bin_sizes %>%
711 # reorder
712 select(c(host_label, path, num_bytes)) %>%
713 left_join(bytecode_size, by = c('host_label')) %>%
714 mutate(native_code_size = num_bytes - bytecode_size) ->
715 sizes
716
717 # paths look like _tmp/ovm-build/bin/clang/oils_cpp.stripped
718 native_sizes %>%
719 select(c(host_label, path, num_bytes)) %>%
720 mutate(host_label = paste("host ", host_label),
721 binary = basename(path),
722 compiler = basename(dirname(path)),
723 ) %>%
724 select(-c(path)) %>%
725 spread(key = c(host_label), value = num_bytes) %>%
726 arrange(compiler, binary) ->
727 native_sizes
728
729 # NOTE: These don't have the host and compiler.
730 writeTsv(times, file.path(out_dir, 'times'))
731 writeTsv(bytecode_size, file.path(out_dir, 'bytecode-size'))
732 writeTsv(sizes, file.path(out_dir, 'sizes'))
733 writeTsv(native_sizes, file.path(out_dir, 'native-sizes'))
734
735 # TODO: I want a size report too
736 #writeCsv(sizes, file.path(out_dir, 'sizes'))
737}
738
739unique_stdout_md5sum = function(t, num_expected) {
740 u = n_distinct(t$stdout_md5sum)
741 if (u != num_expected) {
742 t %>% select(c(host_name, task_name, arg1, arg2, runtime_name, stdout_md5sum)) %>% print()
743 stop(sprintf('Expected %d unique md5sums, got %d', num_expected, u))
744 }
745}
746
747ComputeReport = function(in_dir, out_dir) {
748 # TSV file, not CSV
749 times = read.table(file.path(in_dir, 'times.tsv'), header=T)
750 print(times)
751
752 times %>% filter(status != 0) -> failed
753 if (nrow(failed) != 0) {
754 print(failed)
755 stop('Some compute tasks failed')
756 }
757
758 #
759 # Check correctness
760 #
761
762 times %>% filter(task_name == 'hello') %>% unique_stdout_md5sum(1)
763 times %>% filter(task_name == 'fib') %>% unique_stdout_md5sum(1)
764 times %>% filter(task_name == 'word_freq') %>% unique_stdout_md5sum(1)
765 # 3 different inputs
766 times %>% filter(task_name == 'parse_help') %>% unique_stdout_md5sum(3)
767
768 times %>% filter(task_name == 'bubble_sort') %>% unique_stdout_md5sum(2)
769
770 # TODO:
771 # - oils_cpp doesn't implement unicode LANG=C
772 # - bash behaves differently on your desktop vs. in the container
773 # - might need layer-locales in the image?
774
775 #times %>% filter(task_name == 'palindrome' & arg1 == 'unicode') %>% unique_stdout_md5sum(1)
776 # Ditto here
777 #times %>% filter(task_name == 'palindrome' & arg1 == 'bytes') %>% unique_stdout_md5sum(1)
778
779 #
780 # Find distinct shells and hosts, and label them for readability.
781 #
782
783 # Runtimes are called shells, as a hack for code reuse
784 times %>%
785 mutate(shell_name = runtime_name, shell_hash = runtime_hash) %>%
786 select(c(host_name, host_hash, shell_name, shell_hash)) ->
787 tmp
788
789 distinct_hosts = DistinctHosts(tmp)
790 Log('')
791 Log('Distinct hosts')
792 print(distinct_hosts)
793
794 distinct_shells = DistinctShells(tmp)
795 Log('')
796 Log('Distinct runtimes')
797 print(distinct_shells)
798
799 num_hosts = nrow(distinct_hosts)
800
801 times %>%
802 select(-c(status, stdout_md5sum, stdout_filename, host_hash, runtime_hash)) %>%
803 mutate(runtime_label = ShellLabels(runtime_name, runtime_hash, num_hosts),
804 elapsed_ms = elapsed_secs * 1000,
805 user_ms = user_secs * 1000,
806 sys_ms = sys_secs * 1000,
807 max_rss_MB = max_rss_KiB * 1024 / 1e6) %>%
808 select(-c(runtime_name, elapsed_secs, user_secs, sys_secs, max_rss_KiB)) %>%
809 arrange(host_name, task_name, arg1, arg2, user_ms) ->
810 details
811
812 times %>%
813 mutate(
814 runtime_label = ShellLabels(runtime_name, runtime_hash, num_hosts),
815 stdout_md5sum_HREF = file.path('tmp', task_name, stdout_filename)) %>%
816 select(c(host_name, task_name, arg1, arg2, runtime_label,
817 stdout_md5sum, stdout_md5sum_HREF)) ->
818 stdout_files
819
820 details %>% filter(task_name == 'hello') %>% select(-c(task_name)) -> hello
821 details %>% filter(task_name == 'fib') %>% select(-c(task_name)) -> fib
822 details %>% filter(task_name == 'word_freq') %>% select(-c(task_name)) -> word_freq
823 # There's no arg2
824 details %>% filter(task_name == 'parse_help') %>% select(-c(task_name, arg2)) -> parse_help
825
826 details %>% filter(task_name == 'bubble_sort') %>% select(-c(task_name)) -> bubble_sort
827 details %>% filter(task_name == 'palindrome' & arg1 == 'unicode') %>% select(-c(task_name)) -> palindrome
828
829 precision = ColumnPrecision(list(max_rss_MB = 1), default = 0)
830 writeTsv(details, file.path(out_dir, 'details'), precision)
831
832 writeTsv(stdout_files, file.path(out_dir, 'stdout_files'), precision)
833
834 writeTsv(hello, file.path(out_dir, 'hello'), precision)
835 writeTsv(fib, file.path(out_dir, 'fib'), precision)
836 writeTsv(word_freq, file.path(out_dir, 'word_freq'), precision)
837 writeTsv(parse_help, file.path(out_dir, 'parse_help'), precision)
838
839 writeTsv(bubble_sort, file.path(out_dir, 'bubble_sort'), precision)
840 writeTsv(palindrome, file.path(out_dir, 'palindrome'), precision)
841
842 WriteProvenance(distinct_hosts, distinct_shells, out_dir, tsv = T)
843}
844
845WriteOneTask = function(times, out_dir, task_name, precision) {
846 times %>%
847 filter(task == task_name) %>%
848 select(-c(task)) -> subset
849
850 writeTsv(subset, file.path(out_dir, task_name), precision)
851}
852
853SHELL_ORDER = c('dash',
854 'bash',
855 'zsh',
856 '_bin/cxx-opt+bumpleak/osh',
857 '_bin/cxx-opt+bumproot/osh',
858 '_bin/cxx-opt+bumpsmall/osh',
859 '_bin/cxx-opt/osh',
860 '_bin/cxx-opt+nopool/osh')
861
862GcReport = function(in_dir, out_dir) {
863 times = read.table(file.path(in_dir, 'raw/times.tsv'), header=T)
864 gc_stats = read.table(file.path(in_dir, 'stage1/gc_stats.tsv'), header=T)
865
866 times %>% filter(status != 0) -> failed
867 if (nrow(failed) != 0) {
868 print(failed)
869 stop('Some gc tasks failed')
870 }
871
872 # Change units and order columns
873 times %>%
874 arrange(task, factor(sh_path, levels = SHELL_ORDER)) %>%
875 mutate(elapsed_ms = elapsed_secs * 1000,
876 user_ms = user_secs * 1000,
877 sys_ms = sys_secs * 1000,
878 max_rss_MB = max_rss_KiB * 1024 / 1e6,
879 shell_label = ShellLabelFromPath(sh_path)
880 ) %>%
881 select(c(join_id, task, elapsed_ms, user_ms, sys_ms, max_rss_MB, shell_label,
882 shell_runtime_opts)) ->
883 times
884
885 # Join and order columns
886 gc_stats %>% left_join(times, by = c('join_id')) %>%
887 arrange(desc(task)) %>%
888 mutate(allocated_MB = bytes_allocated / 1e6) %>%
889 # try to make the table skinnier
890 rename(num_gc_done = num_collections) %>%
891 select(task, elapsed_ms, max_gc_millis, total_gc_millis,
892 allocated_MB, max_rss_MB, num_allocated,
893 num_gc_points, num_gc_done, gc_threshold, num_growths, max_survived,
894 shell_label) ->
895 gc_stats
896
897 times %>% select(-c(join_id)) -> times
898
899
900 precision = ColumnPrecision(list(max_rss_MB = 1, allocated_MB = 1),
901 default = 0)
902
903 writeTsv(times, file.path(out_dir, 'times'), precision)
904 writeTsv(gc_stats, file.path(out_dir, 'gc_stats'), precision)
905
906 tasks = c('parse.configure-coreutils',
907 'parse.configure-cpython',
908 'parse.abuild',
909 'ex.compute-fib',
910 'ex.bashcomp-parse-help',
911 'ex.abuild-print-help')
912 # Write out separate rows
913 for (task in tasks) {
914 WriteOneTask(times, out_dir, task, precision)
915 }
916}
917
918GcCachegrindReport = function(in_dir, out_dir) {
919 times = readTsv(file.path(in_dir, 'raw/times.tsv'))
920 counts = readTsv(file.path(in_dir, 'stage1/cachegrind.tsv'))
921
922 times %>% filter(status != 0) -> failed
923 if (nrow(failed) != 0) {
924 print(failed)
925 stop('Some gc tasks failed')
926 }
927
928 print(times)
929 print(counts)
930
931 counts %>% left_join(times, by = c('join_id')) %>%
932 mutate(million_irefs = irefs / 1e6) %>%
933 select(c(million_irefs, task, sh_path, shell_runtime_opts)) %>%
934 arrange(factor(sh_path, levels = SHELL_ORDER)) ->
935 counts
936
937 precision = NULL
938 tasks = c('parse.abuild', 'ex.compute-fib')
939 for (task in tasks) {
940 WriteOneTask(counts, out_dir, task, precision)
941 }
942}
943
944MyCppReport = function(in_dir, out_dir) {
945 times = readTsv(file.path(in_dir, 'benchmark-table.tsv'))
946 print(times)
947
948 times %>% filter(status != 0) -> failed
949 if (nrow(failed) != 0) {
950 print(failed)
951 stop('Some mycpp tasks failed')
952 }
953
954 # Don't care about elapsed and system
955 times %>% select(-c(status, elapsed_secs, bin, task_out)) %>%
956 mutate(example_name_HREF = mycppUrl(example_name),
957 user_ms = user_secs * 1000,
958 sys_ms = sys_secs * 1000,
959 max_rss_MB = max_rss_KiB * 1024 / 1e6) %>%
960 select(-c(user_secs, sys_secs, max_rss_KiB)) ->
961 details
962
963 details %>% select(-c(sys_ms, max_rss_MB)) %>%
964 spread(key = impl, value = user_ms) %>%
965 mutate(`C++ : Python` = `C++` / Python) %>%
966 arrange(`C++ : Python`) ->
967 user_time
968
969 details %>% select(-c(user_ms, max_rss_MB)) %>%
970 spread(key = impl, value = sys_ms) %>%
971 mutate(`C++ : Python` = `C++` / Python) %>%
972 arrange(`C++ : Python`) ->
973 sys_time
974
975 details %>% select(-c(user_ms, sys_ms)) %>%
976 spread(key = impl, value = max_rss_MB) %>%
977 mutate(`C++ : Python` = `C++` / Python) %>%
978 arrange(`C++ : Python`) ->
979 max_rss
980
981 # Sometimes it speeds up by more than 10x
982 precision1 = ColumnPrecision(list(`C++ : Python` = 3), default = 0)
983 writeTsv(user_time, file.path(out_dir, 'user_time'), precision1)
984 writeTsv(sys_time, file.path(out_dir, 'sys_time'), precision1)
985
986 precision2 = ColumnPrecision(list(`C++ : Python` = 2), default = 1)
987 writeTsv(max_rss, file.path(out_dir, 'max_rss'), precision2)
988
989 writeTsv(details, file.path(out_dir, 'details'))
990}
991
992UftraceTaskReport = function(env, task_name, summaries) {
993 # Need this again after redirect
994 MaybeDisableColor(stdout())
995
996 task_env = env[[task_name]]
997
998 untyped = task_env$untyped
999 typed = task_env$typed
1000 strings = task_env$strings
1001 slabs = task_env$slabs
1002 reserve = task_env$reserve
1003
1004 string_overhead = 17 # GC header (8) + len (4) + hash value (4) + NUL (1)
1005 strings %>% mutate(obj_len = str_len + string_overhead) -> strings
1006
1007 # TODO: Output these totals PER WORKLOAD, e.g. parsing big/small, executing
1008 # big/small
1009 #
1010 # And then zoom in on distributions as well
1011
1012 num_allocs = nrow(untyped)
1013 total_bytes = sum(untyped$obj_len)
1014
1015 untyped %>% group_by(obj_len) %>% count() %>% ungroup() -> untyped_hist
1016 #print(untyped_hist)
1017
1018 untyped_hist %>%
1019 mutate(n_less_than = cumsum(n),
1020 percent = n_less_than * 100.0 / num_allocs) ->
1021 alloc_sizes
1022
1023 a24 = untyped_hist %>% filter(obj_len <= 24)
1024 a48 = untyped_hist %>% filter(obj_len <= 48)
1025 a96 = untyped_hist %>% filter(obj_len <= 96)
1026
1027 allocs_24_bytes_or_less = sum(a24$n) * 100.0 / num_allocs
1028 allocs_48_bytes_or_less = sum(a48$n) * 100.0 / num_allocs
1029 allocs_96_bytes_or_less = sum(a96$n) * 100.0 / num_allocs
1030
1031 Log('Percentage of allocs less than 48 bytes: %.1f', allocs_48_bytes_or_less)
1032
1033 options(tibble.print_min=25)
1034
1035 Log('')
1036 Log('All allocations')
1037 print(alloc_sizes %>% head(22))
1038 print(alloc_sizes %>% tail(5))
1039
1040 Log('')
1041 Log('Common Sizes')
1042 print(untyped_hist %>% arrange(desc(n)) %>% head(8))
1043
1044 Log('')
1045 Log(' %s total allocations, total bytes = %s', commas(num_allocs), commas(total_bytes))
1046 Log('')
1047
1048 Log('Typed allocations')
1049
1050 num_typed = nrow(typed)
1051
1052 typed %>% group_by(func_name) %>% count() %>% ungroup() %>%
1053 mutate(percent = n * 100.0 / num_typed) %>%
1054 arrange(desc(n)) -> most_common_types
1055
1056 print(most_common_types %>% head(20))
1057 print(most_common_types %>% tail(5))
1058
1059 lists = typed %>% filter(str_starts(func_name, ('List<')))
1060 #print(lists)
1061
1062 num_lists = nrow(lists)
1063 total_list_bytes = num_lists * 24 # sizeof List<T> head is hard-coded
1064
1065 Log('')
1066 Log('%s typed allocs, including %s List<T>', commas(num_typed), commas(num_lists))
1067 Log('%.2f%% of allocs are typed', num_typed * 100 / num_allocs)
1068 Log('')
1069
1070 #
1071 # Strings
1072 #
1073
1074 num_strings = nrow(strings)
1075 total_string_bytes = sum(strings$obj_len)
1076
1077 strings %>% group_by(str_len) %>% count() %>% ungroup() %>%
1078 mutate(n_less_than = cumsum(n),
1079 percent = n_less_than * 100.0 / num_strings) ->
1080 string_lengths
1081
1082 strs_6_bytes_or_less = string_lengths %>% filter(str_len == 6) %>% select(percent)
1083 strs_14_bytes_or_less = string_lengths %>% filter(str_len == 14) %>% select(percent)
1084
1085 # Parse workload
1086 # 62% of strings <= 6 bytes
1087 # 84% of strings <= 14 bytes
1088
1089 Log('Str - NewStr() and OverAllocatedStr()')
1090 print(string_lengths %>% head(16))
1091 print(string_lengths %>% tail(5))
1092 Log('')
1093
1094 Log('%s string allocations, total length = %s, total bytes = %s', commas(num_strings),
1095 commas(sum(strings$str_len)), commas(total_string_bytes))
1096 Log('')
1097 Log('%.2f%% of allocs are strings', num_strings * 100 / num_allocs)
1098 Log('%.2f%% of bytes are strings', total_string_bytes * 100 / total_bytes)
1099 Log('')
1100
1101 #
1102 # Slabs
1103 #
1104
1105 Log('NewSlab()')
1106
1107 num_slabs = nrow(slabs)
1108 slabs %>% group_by(slab_len) %>% count() %>% ungroup() %>%
1109 mutate(n_less_than = cumsum(n),
1110 percent = n_less_than * 100.0 / num_slabs) ->
1111 slab_lengths
1112
1113 slabs %>% group_by(func_name) %>% count() %>% ungroup() %>%
1114 arrange(desc(n)) -> slab_types
1115
1116 Log(' Lengths')
1117 print(slab_lengths %>% head())
1118 print(slab_lengths %>% tail(5))
1119 Log('')
1120
1121 Log(' Slab Types')
1122 print(slab_types %>% head())
1123 print(slab_types %>% tail(5))
1124 Log('')
1125
1126 total_slab_items = sum(slabs$slab_len)
1127
1128 Log('%s slabs, total items = %s', commas(num_slabs),
1129 commas(sum(slabs$slab_len)))
1130 Log('%.2f%% of allocs are slabs', num_slabs * 100 / num_allocs)
1131 Log('')
1132
1133 #
1134 # reserve() calls
1135 #
1136
1137 # There should be strictly more List::reserve() calls than NewSlab
1138
1139 Log('::reserve(int n)')
1140 Log('')
1141
1142 num_reserve = nrow(reserve)
1143 reserve %>% group_by(num_items) %>% count() %>% ungroup() %>%
1144 mutate(n_less_than = cumsum(n),
1145 percent = n_less_than * 100.0 / num_reserve) ->
1146 reserve_args
1147
1148 Log(' Num Items')
1149 print(reserve_args %>% head(15))
1150 print(reserve_args %>% tail(5))
1151 Log('')
1152
1153 Log('%s reserve() calls, total items = %s', commas(num_reserve),
1154 commas(sum(reserve$num_items)))
1155 Log('')
1156
1157 # Accounting for all allocations!
1158 Log('Untyped: %s', commas(num_allocs))
1159 Log('Typed + Str + Slab: %s', commas(num_typed + num_strings + num_slabs))
1160 Log('')
1161
1162 num_other_typed = num_typed - num_lists
1163
1164 # Summary table
1165 stats = tibble(task = task_name,
1166 total_bytes_ = commas(total_bytes),
1167 num_allocs_ = commas(num_allocs),
1168 sum_typed_strs_slabs = commas(num_typed + num_strings + num_slabs),
1169 num_reserve_calls = commas(num_reserve),
1170
1171 percent_list_allocs = Percent(num_lists, num_allocs),
1172 percent_slab_allocs = Percent(num_slabs, num_allocs),
1173 percent_string_allocs = Percent(num_strings, num_allocs),
1174 percent_other_typed_allocs = Percent(num_other_typed, num_allocs),
1175
1176 percent_list_bytes = Percent(total_list_bytes, total_bytes),
1177 percent_string_bytes = Percent(total_string_bytes, total_bytes),
1178
1179 allocs_24_bytes_or_less = sprintf('%.1f%%', allocs_24_bytes_or_less),
1180 allocs_48_bytes_or_less = sprintf('%.1f%%', allocs_48_bytes_or_less),
1181 allocs_96_bytes_or_less = sprintf('%.1f%%', allocs_96_bytes_or_less),
1182
1183 strs_6_bytes_or_less = sprintf('%.1f%%', strs_6_bytes_or_less),
1184 strs_14_bytes_or_less = sprintf('%.1f%%', strs_14_bytes_or_less),
1185 )
1186 summaries$stats[[task_name]] = stats
1187
1188 summaries$most_common_types[[task_name]] = most_common_types
1189}
1190
1191LoadUftraceTsv = function(in_dir, env) {
1192 for (task in list.files(in_dir)) {
1193 Log('Loading data for task %s', task)
1194 base_dir = file.path(in_dir, task)
1195
1196 task_env = new.env()
1197 env[[task]] = task_env
1198
1199 # TSV file, not CSV
1200 task_env$untyped = readTsv(file.path(base_dir, 'all-untyped.tsv'))
1201 task_env$typed = readTsv(file.path(base_dir, 'typed.tsv'))
1202 task_env$strings = readTsv(file.path(base_dir, 'strings.tsv'))
1203 task_env$slabs = readTsv(file.path(base_dir, 'slabs.tsv'))
1204 task_env$reserve = readTsv(file.path(base_dir, 'reserve.tsv'))
1205
1206 # median string length is 4, mean is 9.5!
1207 Log('UNTYPED')
1208 print(summary(task_env$untyped))
1209 Log('')
1210
1211 Log('TYPED')
1212 print(summary(task_env$typed))
1213 Log('')
1214
1215 Log('STRINGS')
1216 print(summary(task_env$strings))
1217 Log('')
1218
1219 Log('SLABS')
1220 print(summary(task_env$slabs))
1221 Log('')
1222
1223 Log('RESERVE')
1224 print(summary(task_env$reserve))
1225 Log('')
1226 }
1227}
1228
1229Percent = function(n, total) {
1230 sprintf('%.1f%%', n * 100.0 / total)
1231}
1232
1233PrettyPrintLong = function(d) {
1234 tr = t(d) # transpose
1235
1236 row_names = rownames(tr)
1237
1238 for (i in 1:nrow(tr)) {
1239 row_name = row_names[i]
1240 cat(sprintf('%26s', row_name)) # calculated min width manually
1241 cat(sprintf('%20s', tr[i,]))
1242 cat('\n')
1243
1244 # Extra spacing
1245 if (row_name %in% c('num_reserve_calls',
1246 'percent_string_bytes',
1247 'percent_other_typed_allocs',
1248 'allocs_96_bytes_or_less')) {
1249 cat('\n')
1250 }
1251 }
1252}
1253
1254
1255UftraceReport = function(env, out_dir) {
1256 # summaries$stats should be a list of 1-row data frames
1257 # summaries$top_types should be a list of types
1258 summaries = new.env()
1259
1260 for (task_name in names(env)) {
1261 report_out = file.path(out_dir, paste0(task_name, '.txt'))
1262
1263 Log('Making report for task %s -> %s', task_name, report_out)
1264
1265 sink(file = report_out)
1266 UftraceTaskReport(env, task_name, summaries)
1267 sink() # reset
1268 }
1269 Log('')
1270
1271 # Concate all the data frames added to summary
1272 stats = bind_rows(as.list(summaries$stats))
1273
1274 sink(file = file.path(out_dir, 'summary.txt'))
1275 #print(stats)
1276 #Log('')
1277
1278 PrettyPrintLong(stats)
1279 Log('')
1280
1281 mct = summaries$most_common_types
1282 for (task_name in names(mct)) {
1283 Log('Common types in workload %s', task_name)
1284 Log('')
1285
1286 print(mct[[task_name]] %>% head(5))
1287 Log('')
1288 }
1289 sink()
1290
1291 # For the REPL
1292 return(list(stats = stats))
1293}
1294
1295main = function(argv) {
1296 action = argv[[1]]
1297 in_dir = argv[[2]]
1298 out_dir = argv[[3]]
1299
1300 if (action == 'osh-parser') {
1301 ParserReport(in_dir, out_dir)
1302
1303 } else if (action == 'osh-runtime') {
1304 RuntimeReport(in_dir, out_dir)
1305
1306 } else if (action == 'vm-baseline') {
1307 VmBaselineReport(in_dir, out_dir)
1308
1309 } else if (action == 'ovm-build') {
1310 OvmBuildReport(in_dir, out_dir)
1311
1312 } else if (action == 'compute') {
1313 ComputeReport(in_dir, out_dir)
1314
1315 } else if (action == 'gc') {
1316 GcReport(in_dir, out_dir)
1317
1318 } else if (action == 'gc-cachegrind') {
1319 GcCachegrindReport(in_dir, out_dir)
1320
1321 } else if (action == 'mycpp') {
1322 MyCppReport(in_dir, out_dir)
1323
1324 } else if (action == 'uftrace') {
1325 d = new.env()
1326 LoadUftraceTsv(in_dir, d)
1327 UftraceReport(d, out_dir)
1328
1329 } else {
1330 Log("Invalid action '%s'", action)
1331 quit(status = 1)
1332 }
1333 Log('PID %d done', Sys.getpid())
1334}
1335
1336if (length(sys.frames()) == 0) {
1337 # increase ggplot font size globally
1338 #theme_set(theme_grey(base_size = 20))
1339
1340 main(commandArgs(TRUE))
1341}