| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Main file for test-oils.xshar
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # devtools/test-oils.sh <function name>
|
| 7 | #
|
| 8 | # It will contain
|
| 9 | #
|
| 10 | # _release/
|
| 11 | # oils-for-unix.tar
|
| 12 | # benchmarks/
|
| 13 | # time-helper.c
|
| 14 | # osh-runtime.sh
|
| 15 | #
|
| 16 | # It will run benchmarks, and then upload a TSV file to a server.
|
| 17 | #
|
| 18 | # The TSV file will be labeled with
|
| 19 | #
|
| 20 | # - git commit that created the xshar file (in oilshell/oil)
|
| 21 | # - date
|
| 22 | # - label: github actions / sourcehut
|
| 23 | # - and then we'll also have provenance and system info
|
| 24 | # - machine name, OS, CPUs, etc.
|
| 25 |
|
| 26 | set -o nounset
|
| 27 | set -o pipefail
|
| 28 | set -o errexit
|
| 29 |
|
| 30 | source test/common.sh # die
|
| 31 |
|
| 32 | OILS_VERSION=$(head -n 1 oil-version.txt)
|
| 33 |
|
| 34 | REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
|
| 35 |
|
| 36 | FLAG_num_iters=1 # iterations
|
| 37 | FLAG_num_shells=1
|
| 38 | FLAG_num_workloads=1
|
| 39 |
|
| 40 | print-help() {
|
| 41 | # Other flags:
|
| 42 | #
|
| 43 | # --host host to upload to?
|
| 44 | # --auth allow writing to host
|
| 45 | # --no-taskset disable taskset?
|
| 46 |
|
| 47 | local xshar_path=test-oils.xshar # hard-coded for now
|
| 48 |
|
| 49 | cat <<EOF
|
| 50 | Usage: $xshar_path ACTION FLAGS*
|
| 51 |
|
| 52 | Actions:
|
| 53 |
|
| 54 | osh-runtime (only one supported)
|
| 55 |
|
| 56 | Flags:
|
| 57 | -n --num-iters (default: 1) Run everything this number of times.
|
| 58 |
|
| 59 | -s --num-shells Run the first N of osh, bash, dash
|
| 60 |
|
| 61 | -w --num-workloads Run the first N of the workloads
|
| 62 |
|
| 63 | Workloads:
|
| 64 | EOF
|
| 65 | benchmarks/osh-runtime.sh print-workloads
|
| 66 | cat <<EOF
|
| 67 |
|
| 68 | Example:
|
| 69 |
|
| 70 | $xshar_path osh-runtime --num-iters 2 --num-shells 2 --num-workloads 3
|
| 71 |
|
| 72 | will run this benchmark matrix 2 times:
|
| 73 |
|
| 74 | (osh, bash) X (hello-world, bin-true, configure-cpython)
|
| 75 |
|
| 76 | About xshar:
|
| 77 |
|
| 78 | This is a self-extracting executable. It contains:
|
| 79 |
|
| 80 | 1. The oils-for-unix tarball, which can be compiled on any machine easily
|
| 81 | 2. Benchmarking scripts
|
| 82 | 3. This harness, which compiles the tarball, accepts flags, runs benchmarks.
|
| 83 |
|
| 84 | EOF
|
| 85 | }
|
| 86 |
|
| 87 | print-version() {
|
| 88 | echo "$0 was built from git commit ${XSHAR_GIT_COMMIT:-?}"
|
| 89 | }
|
| 90 |
|
| 91 | parse-flags-osh-runtime() {
|
| 92 | ### Sets global vars FLAG_*
|
| 93 |
|
| 94 | while test $# -ne 0; do
|
| 95 | case "$1" in
|
| 96 | -v|--version)
|
| 97 | print-version
|
| 98 | exit
|
| 99 | ;;
|
| 100 | -h|--help)
|
| 101 | print-help
|
| 102 | exit
|
| 103 | ;;
|
| 104 |
|
| 105 | -n|--num-iters)
|
| 106 | if test $# -eq 1; then
|
| 107 | die "-n / --num-iters requires an argument"
|
| 108 | fi
|
| 109 | shift
|
| 110 | FLAG_num_iters=$1
|
| 111 | ;;
|
| 112 |
|
| 113 | -s|--num-shells)
|
| 114 | if test $# -eq 1; then
|
| 115 | die "-s / --num-shells requires an argument"
|
| 116 | fi
|
| 117 | shift
|
| 118 | FLAG_num_shells=$1
|
| 119 | ;;
|
| 120 |
|
| 121 | -w|--num-workloads)
|
| 122 | if test $# -eq 1; then
|
| 123 | die "-w / --num-workloads requires an argument"
|
| 124 | fi
|
| 125 | shift
|
| 126 | FLAG_num_shells=$1
|
| 127 | ;;
|
| 128 |
|
| 129 | *)
|
| 130 | die "Invalid flag '$1'"
|
| 131 | ;;
|
| 132 | esac
|
| 133 | shift
|
| 134 | done
|
| 135 | }
|
| 136 |
|
| 137 | osh-runtime() {
|
| 138 | # $XSHAR_DIR looks like like $REPO_ROOT
|
| 139 |
|
| 140 | parse-flags-osh-runtime "$@"
|
| 141 | echo num_iters=$FLAG_num_iters
|
| 142 | echo num_shells=$FLAG_num_shells
|
| 143 | echo num_workloads=$FLAG_num_workloads
|
| 144 |
|
| 145 | local time_py="${XSHAR_DIR:-$REPO_ROOT}/benchmarks/time_.py"
|
| 146 | build/py.sh time-helper
|
| 147 |
|
| 148 | # Extract and compile the tarball
|
| 149 | # Similar to devtools/release-native.sh test-tar
|
| 150 | local tmp=_tmp/oils-tar
|
| 151 | mkdir -p $tmp
|
| 152 |
|
| 153 | pushd $tmp
|
| 154 | tar -x < ../../_release/oils-for-unix.tar
|
| 155 |
|
| 156 | pushd oils-for-unix-$OILS_VERSION
|
| 157 | build/native.sh tarball-demo
|
| 158 |
|
| 159 | local osh=$PWD/_bin/cxx-opt-sh/osh
|
| 160 |
|
| 161 | # Smoke test
|
| 162 | $time_py --tsv --rusage -- \
|
| 163 | $osh -c 'echo "smoke test: osh and time_.py"'
|
| 164 |
|
| 165 | popd
|
| 166 | popd
|
| 167 |
|
| 168 | benchmarks/osh-runtime.sh test-oils-run $osh \
|
| 169 | $FLAG_num_shells $FLAG_num_workloads $FLAG_num_iters
|
| 170 | }
|
| 171 |
|
| 172 | demo() {
|
| 173 | ### Show how we compile the code
|
| 174 |
|
| 175 | local time_py="$PWD/benchmarks/time_.py"
|
| 176 |
|
| 177 | build/py.sh time-helper
|
| 178 |
|
| 179 | # Extract and compile the tarball
|
| 180 | # Similar to devtools/release-native.sh test-tar
|
| 181 |
|
| 182 | local tmp=_tmp/xshar-demo
|
| 183 | mkdir -p $tmp
|
| 184 |
|
| 185 | pushd $tmp
|
| 186 | tar -x < ../../_release/oils-for-unix.tar
|
| 187 |
|
| 188 | pushd oils-for-unix-$OILS_VERSION
|
| 189 | build/native.sh tarball-demo
|
| 190 |
|
| 191 | local osh=$PWD/_bin/cxx-opt-sh/osh
|
| 192 |
|
| 193 | $time_py --tsv --rusage -o demo.tsv -- \
|
| 194 | $osh -c 'sleep 0.1; echo "hi from osh"'
|
| 195 | cat demo.tsv
|
| 196 |
|
| 197 | popd
|
| 198 |
|
| 199 | popd
|
| 200 |
|
| 201 | #time OILS_GC_STATS=1 $osh Python-2.7.13/configure
|
| 202 | }
|
| 203 |
|
| 204 | if test $# -eq 0; then
|
| 205 | print-help
|
| 206 | else
|
| 207 | case "$1" in
|
| 208 | -v|--version)
|
| 209 | print-version
|
| 210 | exit
|
| 211 | ;;
|
| 212 | -h|--help)
|
| 213 | print-help
|
| 214 | exit
|
| 215 | ;;
|
| 216 | esac
|
| 217 |
|
| 218 | "$@"
|
| 219 | fi
|