2
# shellcheck disable=SC1090,SC2034,SC2154,SC2039,SC1007,SC2207,SC2145,SC2155,SC2206
3
## Don't import this file directly.
5
## TODO: debug the spectacular failure this causes..
8
. "${__COMMON_SRCROOT}/scripts/benchmarking/lib-nix.sh"
11
## This depends on the setup done by scripts/common.sh
19
## This only prints if ran from the top-level shell process.
20
if test -z "${lib_recursing}"; then oprint "$@"; fi
25
if test -n "${verbose}${debug}"; then echo "-- $*" >&2; fi
29
## This only prints if either in debug mode,
30
## or ran from the top-level shell process.
31
if test -z "${lib_recursing}" -o -n "${debug}"; then vprint "$@"; fi
36
if test -n "${debug}"; then echo "-- $*" >&2; fi
41
echo "-- FATAL: $*" >&2
46
local pkg="$1" exe="${2:-${pkg}}"
47
vprint "prebuilding the \"$pkg:$exe\" executable in \"${mode}\" mode.."
48
run --no-stats "$pkg" "$exe" --help >/dev/null || true
53
if test -n "${verbose}"
67
## This nightmare below (minus the last line) does one simple thing:
68
## ..it ensures the --build-extra argument has the mode-specific argument
69
## that muffles output from the mode-appropriate build tool.
73
--build-extra ) bld_extra=$2; shift;;
74
* ) break;; esac; shift; done
76
nix ) bld_extra="--no-build-output --quiet ${bld_extra}";;
77
cabal ) bld_extra="-v0 ${bld_extra}";;
78
stack | stack-nix ) bld_extra="--silent ${bld_extra}";; esac;
80
actually_run --build-extra "${bld_extra}" "$@"
87
dprint "actually_run: ${ARGS[@]@Q}"
89
local profile= profile_suffix= user_suffix= profile_prefix= profile_file=
90
local profile_root='./profile'
96
do # ARGS=("$@"); dprint "handling: ${ARGS[@]@Q}"
98
--build-extra ) bld_extra="$2"; shift;;
99
--profile ) profile=$2; shift;;
100
--profile-suffix ) user_suffix=.$2; shift;;
101
--no-stats ) stats=;;
103
git-head | HEAD ) tag="$(git symbolic-ref HEAD | sed 's,.*/,,g')";;
104
* ) tag=$2;; esac; shift;;
105
* ) break;; esac; shift; done
106
dprint "actually_run binary extra args: $*"
109
profile_prefix="${profile_root}/$(generate_mnemonic "${tag}")${user_suffix}"
111
time ) vprint "profiling: time"
112
profmode='-P'; profile_suffix="prof";;
113
space ) vprint "profiling: space, by default cost centre"
114
profmode='-h'; profile_suffix="hp";;
115
space-module ) vprint "profiling: space, by module"
116
profmode='-hm'; profile_suffix="hp";;
117
space-closure ) vprint "profiling: space, by closure"
118
profmode='-hd'; profile_suffix="hp";;
119
space-type ) vprint "profiling: space, by type"
120
profmode='-hy'; profile_suffix="hp";;
121
space-retainer ) vprint "profiling: space, by retainer"
122
profmode='-hr'; profile_suffix="hp";;
123
space-bio ) vprint "profiling: space, biographic"
124
profmode='-hb'; profile_suffix="hp";
127
* ) fprint "--profile requires a mode argument: time space space-module space-closure space-type space-retainer space-bio"; exit 1;; esac
129
if test -n "${stats}${profile}"
130
then mkdir -p "${profile_root}"
132
if test -n "${stats}"
133
then rtsopts+=" --machine-readable -t${profile_prefix}.stats"
135
if test -n "${profile}"
136
then profile_file="${profile_prefix}${profile_suffix}"
137
# rtsopts="+RTS --machine-readable -l -t${profile_prefix}.stats -po${profile_prefix} -ol ${profile_prefix}.eventlog ";
138
# Sadly GHC 8.6 doesn't support -ol
139
rtsopts+=" -l -po${profile_prefix} ";
141
rtsopts+="${profmode} -RTS";
142
if test "${rtsopts}" = "+RTS -RTS"
144
vprint "RTS options: ${rtsopts}"
145
if test -n "${rtsopts}"
146
then vprint "result prefix: ${profile_prefix}"; fi
148
local pkg="$1"; shift
149
local exe="$1"; shift
152
nix ) X=(run_nix_executable "$pkg" "$exe" "${bld_extra}" ${rtsopts} "$@");;
153
cabal ) X=(cabal v2-run ${bld_extra} exe:$exe -- ${rtsopts} "$@");;
154
stack ) X=(stack ${bld_extra} run $exe -- ${rtsopts} "$@");;
155
stack-nix ) X=(stack ${bld_extra} run --nix $exe -- ${rtsopts} "$@");;
156
* ) echo "INTERNAL ERROR: unknown mode: $mode" >&2; return 1;;
163
if test -f "${exe}.eventlog"
164
then mv "${exe}.eventlog" "${profile_prefix}.eventlog"
166
if test -f "${profile_file}" -a -x "$(command -v profiteur 2>/dev/null)"
167
then profiteur "${profile_file}"
169
if test -f "${profile_file}" -a -x "$(command -v profiterole 2>/dev/null)"
170
then profiterole "${profile_file}"
172
if test -f "${profile_file}" -a -x "$(command -v eventlog2html 2>/dev/null)"
173
then eventlog2html "${profile_prefix}.eventlog"
178
export -f actually_run
181
## Misc stuff, too few to be worth splitting out
183
generate_wordpair() {
185
nix ) nix-shell -p diceware --run 'diceware --no-caps --num 2 --wordlist en_eff -d-' 2>/dev/null || true;;
191
local mnemonic="${1:-$(generate_wordpair)}"
192
local timestamp="$(date +%s)"
193
local commit="$(git rev-parse HEAD | cut -c-8)"
196
if git diff --quiet --exit-code
201
echo "${timestamp}.${commit}.${status}${mnemonic:+.${mnemonic}}"
203
export -f generate_mnemonic