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

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