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