OILS / benchmarks / vm-baseline.sh View on Github | oilshell.org

180 lines, 85 significant
1#!/usr/bin/env bash
2#
3# Do a quick test of virtual memory.
4#
5# Note: This is probably very similar to max RSS of
6# testdata/osh-runtime/hello-world.sh, so it could be retired.
7#
8# Usage:
9# benchmarks/vm-baseline.sh <function name>
10
11set -o nounset
12set -o pipefail
13set -o errexit
14
15REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
16
17source test/common.sh # log
18source benchmarks/common.sh
19source test/tsv-lib.sh # tsv2html
20
21readonly BASE_DIR=_tmp/vm-baseline
22
23measure() {
24 local provenance=$1
25 local host_job_id=$2
26 local base_dir=${3:-_tmp/vm-baseline}
27
28 local out_dir="$base_dir/$host_job_id"
29 mkdir -p $out_dir
30
31 # TODO:
32 # print-tasks should:
33 # - use the whole shell path like _bin/osh
34 # - the host name should be a column
35 # - the join ID can be a file, and construct the task name from that
36 # - Then maybe use tsv_columns_from_files.py like we do with cachegrind
37
38 # - should not
39 # - get shell name from the filename
40 # - get host name from the filename
41 # - should use TSV files
42
43 # Fourth column is the shell.
44 cat $provenance | filter-provenance "${SHELLS[@]}" "$OSH_CPP_REGEX" |
45 while read _ _ _ sh_path shell_hash; do
46
47 local sh_name
48 sh_name=$(basename $sh_path)
49
50 local out="$out_dir/${sh_name}-${shell_hash}.txt"
51
52 # There is a race condition on the status but sleep helps.
53 # Bug fix: ALIVE to prevent exec optimization in OSH and zsh.
54 $sh_path -c 'sleep 0.001; cat /proc/$$/status; echo ALIVE' > $out
55 done
56
57 echo
58 echo "$out_dir:"
59 ls -l $out_dir
60}
61
62# Run a single file through stage 1 and report.
63demo() {
64 local -a job_dirs=($BASE_DIR/lisa.2017-*)
65 local dir1=$BASE_DIR/stage1
66 local dir2=$BASE_DIR/stage2
67
68 mkdir -p $dir1 $dir2
69
70 benchmarks/virtual_memory.py baseline ${job_dirs[-1]} \
71 > $dir1/vm-baseline.tsv
72
73 benchmarks/report.R vm-baseline $dir1 $dir2
74}
75
76# Combine CSV files.
77stage1() {
78 local raw_dir=${1:-$BASE_DIR/raw}
79 local single_machine=${2:-}
80
81 local out=$BASE_DIR/stage1
82 mkdir -p $out
83
84 local base_dir=
85
86 local -a raw=()
87
88 if test -n "$single_machine"; then
89 base_dir=_tmp/vm-baseline
90 local -a m1=( $base_dir/$single_machine.* )
91 raw+=( ${m1[-1]} )
92 else
93 base_dir=../benchmark-data/vm-baseline
94 # Globs are in lexicographical order, which works for our dates.
95 local -a m1=( $base_dir/$MACHINE1.* )
96 local -a m2=( $base_dir/$MACHINE2.* )
97
98 raw+=( ${m1[-1]} ${m2[-1]} )
99 fi
100
101 benchmarks/virtual_memory.py baseline "${raw[@]}" \
102 | tee $out/vm-baseline.tsv
103}
104
105print-report() {
106 local in_dir=$1
107
108 benchmark-html-head 'Virtual Memory Baseline'
109
110 cat <<EOF
111 <body class="width60">
112 <p id="home-link">
113 <a href="/">oilshell.org</a>
114 </p>
115EOF
116
117 cmark << 'EOF'
118## Virtual Memory Baseline
119
120Source code: [oil/benchmarks/vm-baseline.sh](https://github.com/oilshell/oil/tree/master/benchmarks/vm-baseline.sh)
121
122### Memory Used at Startup (MB)
123
124Memory usage is measured in MB (powers of 10), not MiB (powers of 2).
125
126EOF
127 # highlight OSH lines
128 tsv2html --css-class-pattern 'special ^osh' $in_dir/vm-baseline.tsv
129
130 # R code doesn't generate this
131 if false; then
132 cmark <<< '### Shell and Host Details'
133
134 tsv2html $in_dir/shells.tsv
135 tsv2html $in_dir/hosts.tsv
136 fi
137
138 cat <<EOF
139 </body>
140</html>
141EOF
142}
143
144
145#
146# Other
147#
148
149soil-run() {
150 ### Run it on just this machine, and make a report
151
152 rm -r -f $BASE_DIR
153 mkdir -p $BASE_DIR
154
155 local -a osh_bin=( $OSH_CPP_NINJA_BUILD )
156 ninja "${osh_bin[@]}"
157
158 local single_machine='no-host'
159
160 local job_id
161 job_id=$(benchmarks/id.sh print-job-id)
162
163 benchmarks/id.sh shell-provenance-2 \
164 $single_machine $job_id _tmp \
165 bash dash bin/osh "${osh_bin[@]}"
166
167 # TODO: measure* should use print-tasks | run-tasks
168 local provenance=_tmp/provenance.txt
169 local host_job_id="$single_machine.$job_id"
170
171 measure $provenance $host_job_id
172
173 # Make it run on one machine
174 stage1 '' $single_machine
175
176 benchmarks/report.sh stage2 $BASE_DIR
177 benchmarks/report.sh stage3 $BASE_DIR
178}
179
180"$@"