-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathbench.sh
executable file
·82 lines (70 loc) · 2.67 KB
/
bench.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash -li
if [[ "$1" == "help" ]]; then
echo "tool/bench.sh (igv|time) <path_to_bench> [compile] {jvm-ce | jvm-ee | jvm | native}"
echo " * igv mode: dumps to e.g. graal_dumps/micro/dispatch/dispatch-bi-jvm-ce/"
echo " * time mode: appends [timestamp] mean median to ./perf.txt"
echo " (requires datamash to be on path)"
echo " * if no configuration is specified, defaults to jvm-ce"
echo " * run from the root of the repo"
echo " * you can pass a *quoted* wildcarded path, e.g. \"bench/micro/dispatch/*\""
echo " * no spaces in the path! (can't quote in script to support wildcarded paths)"
echo " * config variable:"
echo " - \$BENCH_SLEEP -- time to sleep between benchmark runs in time mode (default: 30)"
echo " - \$BENCH_TIME -- time to run the benchmarks for (default: 30)"
echo " - \$BENCH_TAIL -- number of trailing numbers to compute stats on (default: 15)"
exit 0
fi
BENCH_SLEEP=${BENCH_SLEEP:-30}
BENCH_TIME=${BENCH_TIME:-30}
BENCH_TAIL=${BENCH_TAIL:-15}
bench_mode=$1; shift
bench_path=$1; shift
contains() {
local item=$1; shift
# shellcheck disable=SC2199,SC2076
[[ " $@ " =~ " $item " ]]
}
bench_envs=()
contains jvm "$@" && bench_envs+=(jvm)
contains native "$@" && bench_envs+=(native)
contains jvm-ce "$@" && bench_envs+=(jvm-ce)
contains jvm-ee "$@" && bench_envs+=(jvm-ee)
# shellcheck disable=SC2199
[[ "${bench_envs[@]}" == "" ]] && bench_envs+=(jvm-ce)
if [[ "$1" == "compile" ]]; then
echo "--- compiling ---------------------------------------------------------"
for conf in "${bench_envs[@]}"; do
jt build --env "$conf" --sforceimports
done
echo "--- / compiling -------------------------------------------------------"
fi
format_time() {
local name=$1
while read -r line; do
echo "[$(date +"%Y-%m-%d %T") $name] $line"
done
}
bench() {
local file=$1
local config=$2
local bench_name=$file
bench_name=${bench_name%.rb}
bench_name=${bench_name#bench/}
if [[ $bench_mode == igv ]]; then
local dump_path=graal_dumps/$bench_name-$config
mkdir -p "$dump_path"
jt -u "$config" benchmark "$file" --time "$BENCH_TIME" -- --igv --vm.Djdk.graal.DumpPath="$dump_path"
elif [[ $bench_mode == time ]]; then
jt -u "$config" benchmark "$file" --time "$BENCH_TIME" | tee /dev/tty | tail -n "$BENCH_TAIL" | \
datamash mean 1 median 1 | format_time "$bench_name-$config" >> perf.txt
sleep "$BENCH_SLEEP"
else
echo "Unrecognized mode: $bench_mode"
exit 1
fi
}
for file in $bench_path; do
for config in "${bench_envs[@]}"; do
bench "$file" "$config"
done
done