1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Common functions for benchmarks.
|
4 | #
|
5 |
|
6 | # Include guard.
|
7 | test -n "${__BENCHMARKS_COMMON_SH:-}" && return
|
8 | readonly __BENCHMARKS_COMMON_SH=1
|
9 |
|
10 | #readonly MACHINE1=flanders
|
11 | #readonly MACHINE2=lenny
|
12 |
|
13 | # 2023-11-29: machine1 is still lenny because it has bloaty, which doesn't
|
14 | # work with ELF data emitted by newer GCC on Debian 12
|
15 | readonly MACHINE1=lenny
|
16 | readonly MACHINE2=hoover
|
17 |
|
18 | OIL_VERSION=$(head -n 1 oil-version.txt)
|
19 |
|
20 | # Used by devtools/release.sh
|
21 | readonly BENCHMARK_DATA_OILS=$PWD/../benchmark-data/src/oils-for-unix-$OIL_VERSION
|
22 |
|
23 | readonly OSH_CPP_NINJA_BUILD=_bin/cxx-opt/osh
|
24 |
|
25 | readonly OSH_CPP_SH_BUILD=_bin/cxx-opt-sh/osh
|
26 | readonly YSH_CPP_SH_BUILD=_bin/cxx-opt-sh/ysh
|
27 |
|
28 | readonly OSH_CPP_BENCHMARK_DATA=$BENCHMARK_DATA_OILS/$OSH_CPP_SH_BUILD
|
29 | readonly YSH_CPP_BENCHMARK_DATA=$BENCHMARK_DATA_OILS/$YSH_CPP_SH_BUILD
|
30 |
|
31 | #
|
32 | # Binaries we want to test, which can be overridden
|
33 | #
|
34 |
|
35 | OSH_OVM=${OSH_OVM:-_bin/osh} # This is overridden by devtools/release.sh.
|
36 |
|
37 | readonly OTHER_SHELLS=( bash dash mksh zsh )
|
38 | readonly SHELLS=( ${OTHER_SHELLS[@]} bin/osh $OSH_OVM )
|
39 |
|
40 | # Passed to awk in filter-provenance. TODO: This could be a parameter
|
41 | # Awk wants this to be \\. ? Probably should stop using Awk.
|
42 | readonly OSH_CPP_REGEX='_bin/.*/osh'
|
43 |
|
44 | log() {
|
45 | echo "$@" >&2
|
46 | }
|
47 |
|
48 | # NOTE: This is in {build,test}/common.sh too.
|
49 | die() {
|
50 | log "$0: fatal: $@"
|
51 | exit 1
|
52 | }
|
53 |
|
54 |
|
55 | cmark() {
|
56 | # A filter to making reports
|
57 | PYTHONPATH=. doctools/cmark.py "$@"
|
58 | }
|
59 |
|
60 | # For compatibility, if cell starts with 'osh', apply the 'special' CSS class.
|
61 | csv2html() {
|
62 | web/table/csv2html.py --css-class-pattern 'special ^osh' "$@"
|
63 | }
|
64 |
|
65 | # also in metrics/source-code.sh
|
66 | hist() { sort | uniq -c | sort -n; }
|
67 |
|
68 | html-head() {
|
69 | PYTHONPATH=. doctools/html_head.py "$@"
|
70 | }
|
71 |
|
72 | benchmark-html-head() {
|
73 | local title="$1"
|
74 |
|
75 | local base_url='../../web'
|
76 |
|
77 | html-head --title "$title" \
|
78 | "$base_url/table/table-sort.js" \
|
79 | "$base_url/table/table-sort.css" \
|
80 | "$base_url/base.css"\
|
81 | "$base_url/benchmarks.css"
|
82 | }
|
83 |
|
84 | filter-provenance() {
|
85 | # create a regex bash|dash
|
86 | local pat=$(echo "$@" | sed 's/ /|/g')
|
87 |
|
88 | # Anchor it at the end only. For _bin/cxx-opt/oils-for-unix.stripped and the
|
89 | # ../benchmark-data one.
|
90 | pat="($pat)\$"
|
91 |
|
92 | # 4th column is the shell
|
93 | awk -v pat="$pat" '$4 ~ pat { print }'
|
94 | }
|
95 |
|
96 | maybe-tree() {
|
97 | ### Run tree command if it's installed
|
98 | if command -v tree; then
|
99 | tree "$@"
|
100 | fi
|
101 | }
|