| •1 |
#! /usr/bin/bash |
| 2 |
|
| 3 |
# ASSUMPTIONS: |
| 4 |
# - the OPAM packages, specified by the user, are topologically sorted wrt. to the dependency relationship. |
| 5 |
# - all the variables below are set. |
| 6 |
|
| 7 |
set -e |
| 8 |
|
| 9 |
BENCH_DEBUG= |
| 10 |
|
| 11 |
r='\033[0m' # reset (all attributes off) |
| 12 |
b='\033[1m' # bold |
| 13 |
u='\033[4m' # underline |
| 14 |
nl=$'\n' |
| 15 |
bt='`' # backtick |
| 16 |
start_code_block='```' |
| 17 |
end_code_block='```' |
| 18 |
|
| 19 |
# Check that the required arguments are provided |
| 20 |
|
| 21 |
check_variable () { |
| 22 |
if [ ! -v "$1" ] |
| 23 |
then |
| 24 |
echo "Variable $1 should be set" |
| 25 |
exit 1 |
| 26 |
fi |
| 27 |
} |
| 28 |
|
| 29 |
#check_variable "BUILD_ID" |
| 30 |
#check_variable "BUILD_URL" |
| 31 |
#check_variable "JOB_NAME" |
| 32 |
#check_variable "JENKINS_URL" |
| 33 |
#check_variable "CI_JOB_URL" |
| 34 |
#check_variable "CI_REPOSITORY_URL" |
| 35 |
|
| 36 |
: "${coq_pr_number:=}" |
| 37 |
: "${coq_pr_comment_id:=}" |
| 38 |
: "${new_ocaml_version:=4.14.1}" |
| 39 |
: "${old_ocaml_version:=4.14.1}" |
| 40 |
: "${new_ocaml_flambda:=0}" |
| 41 |
: "${old_ocaml_flambda:=0}" |
| 42 |
: "${new_coq_repository:=${CI_REPOSITORY_URL:-.}}" |
| 43 |
: "${old_coq_repository:=${CI_REPOSITORY_URL:-.}}" |
| 44 |
: "${new_coq_opam_archive_git_uri:=https://github.com/coq/opam-coq-archive.git}" |
| 45 |
: "${old_coq_opam_archive_git_uri:=https://github.com/coq/opam-coq-archive.git}" |
| 46 |
: "${new_coq_opam_archive_git_branch:=master}" |
| 47 |
: "${old_coq_opam_archive_git_branch:=master}" |
| 48 |
: "${new_coq_version:=dev}" |
| 49 |
: "${old_coq_version:=dev}" |
| 50 |
: "${num_of_iterations:=1}" |
| 51 |
: "${timeout:=3h}" |
| 52 |
: "${coq_opam_packages:=rocq-stdlib rocq-bignums coq-hott coq-performance-tests-lite coq-engine-bench-lite rocq-elpi rocq-mathcomp-boot rocq-mathcomp-order rocq-mathcomp-ssreflect rocq-mathcomp-fingroup rocq-mathcomp-algebra rocq-mathcomp-solvable rocq-mathcomp-field rocq-mathcomp-character coq-mathcomp-odd-order coq-mathcomp-analysis coq-math-classes coq-corn coq-compcert rocq-equations rocq-metarocq-utils rocq-metarocq-common rocq-metarocq-template rocq-metarocq-pcuic rocq-metarocq-safechecker rocq-metarocq-erasure rocq-metarocq-translations coq-color coq-coqprime coq-coqutil coq-bedrock2 coq-rewriter coq-fiat-core coq-fiat-parsers coq-fiat-crypto-with-bedrock coq-unimath coq-coquelicot coq-iris-examples coq-verdi coq-verdi-raft coq-fourcolor coq-rewriter-perf-SuperFast coq-vst coq-category-theory coq-neural-net-interp-computed-lite}" |
| 53 |
: "${coq_native:=}" |
| 54 |
|
| 55 |
# example: coq-hott.dev git+https://github.com/some-user/coq-hott#some-branch |
| 56 |
# (make sure to include the version for the opam package, note that just https won't work) |
| 57 |
: "${new_opam_override_urls:=}" |
| 58 |
: "${old_opam_override_urls:=}" |
| 59 |
|
| 60 |
if [ "$CI" ]; then |
| 61 |
: "${new_coq_commit:=$(git rev-parse HEAD^2)}" |
| 62 |
: "${old_coq_commit:=$(git merge-base HEAD^1 $new_coq_commit)}" |
| 63 |
else |
| 64 |
echo New coq commit: |
| 65 |
read -r new_coq_commit |
| 66 |
new_coq_commit=$(git rev-parse "$new_coq_commit") |
| 67 |
echo "new_coq_commit=$new_coq_commit" |
| 68 |
|
| 69 |
echo Old coq commit: |
| 70 |
read -r old_coq_commit |
| 71 |
old_coq_commit=$(git rev-parse "$old_coq_commit") |
| 72 |
echo "old_coq_commit=$old_coq_commit" |
| 73 |
fi |
| 74 |
|
| 75 |
new_ocaml_switch=ocaml-base-compiler.$new_ocaml_version |
| 76 |
old_ocaml_switch=ocaml-base-compiler.$old_ocaml_version |
| 77 |
|
| 78 |
if echo "$num_of_iterations" | grep '^[1-9][0-9]*$' 2> /dev/null > /dev/null; then |
| 79 |
: |
| 80 |
else |
| 81 |
echo |
| 82 |
echo "ERROR: num_of_iterations \"$num_of_iterations\" is not a positive integer." > /dev/stderr |
| 83 |
print_man_page_hint |
| 84 |
exit 1 |
| 85 |
fi |
| 86 |
|
| 87 |
bench_dirname="_bench" |
| 88 |
mkdir -p "${bench_dirname}" |
| 89 |
working_dir="$PWD/${bench_dirname}" |
| 90 |
|
| 91 |
log_dir=$working_dir/logs |
| 92 |
mkdir "$log_dir" |
| 93 |
export COQ_LOG_DIR=$log_dir |
| 94 |
|
| 95 |
echo "DEBUG: ocaml -version = $(ocaml -version)" |
| 96 |
echo "DEBUG: working_dir = $working_dir" |
| 97 |
echo "DEBUG: new_ocaml_switch = $new_ocaml_switch" |
| 98 |
echo "DEBUG: new_coq_repository = $new_coq_repository" |
| 99 |
echo "DEBUG: new_coq_commit = $new_coq_commit" |
| 100 |
echo "DEBUG: new_coq_opam_archive_git_uri = $new_coq_opam_archive_git_uri" |
| 101 |
echo "DEBUG: new_coq_opam_archive_git_branch = $new_coq_opam_archive_git_branch" |
| 102 |
echo "DEBUG: old_ocaml_switch = $old_ocaml_switch" |
| 103 |
echo "DEBUG: old_coq_repository = $old_coq_repository" |
| 104 |
echo "DEBUG: old_coq_commit = $old_coq_commit" |
| 105 |
echo "DEBUG: old_coq_opam_archive_git_uri = $old_coq_opam_archive_git_uri" |
| 106 |
echo "DEBUG: old_coq_opam_archive_git_branch = $old_coq_opam_archive_git_branch" |
| 107 |
echo "DEBUG: num_of_iterations = $num_of_iterations" |
| 108 |
echo "DEBUG: coq_opam_packages = $coq_opam_packages" |
| 109 |
echo "DEBUG: new_opam_override_urls = $new_opam_override_urls" |
| 110 |
echo "DEBUG: old_opam_override_urls = $old_opam_override_urls" |
| 111 |
echo "DEBUG: coq_pr_number = $coq_pr_number" |
| 112 |
echo "DEBUG: coq_pr_comment_id = $coq_pr_comment_id" |
| 113 |
echo "DEBUG: coq_native = $coq_native" |
| 114 |
|
| 115 |
# We put local binaries such as opam in .bin and extend PATH |
| 116 |
BIN=$(pwd)/.bin |
| 117 |
mkdir "$BIN" |
| 118 |
wget https://github.com/ocaml/opam/releases/download/2.3.0/opam-2.3.0-x86_64-linux -O "$BIN"/opam |
| 119 |
chmod +x "$BIN"/opam |
| 120 |
|
| 121 |
export OPAMSKIPUPDATE=1 # stop opam from messing with our pin edits |
| 122 |
|
| 123 |
# generate per file info in test suite and coq_makefile devs |
| 124 |
export TIMED=1 |
| 125 |
|
| 126 |
export PATH="$BIN":$PATH |
| 127 |
|
| 128 |
echo "Global env info:" |
| 129 |
echo "----------------" |
| 130 |
echo "pwd: $PWD" |
| 131 |
echo "path: $PATH" |
| 132 |
echo "opam version: `opam --version`" |
| 133 |
|
| 134 |
number_of_processors=$(cat /proc/cpuinfo | grep '^processor *' | wc -l) |
| 135 |
|
| 136 |
program_name="$0" |
| 137 |
program_path=$(readlink -f "${program_name%/*}") |
| 138 |
|
| 139 |
coqbot_url_prefix="https://coqbot.herokuapp.com/pendulum/" |
| 140 |
|
| 141 |
# -------------------------------------------------------------------------------- |
| 142 |
|
| 143 |
# Some sanity checks of command-line arguments provided by the user that can be done right now. |
| 144 |
|
| 145 |
if which perf > /dev/null; then |
| 146 |
echo -n |
| 147 |
else |
| 148 |
echo > /dev/stderr |
| 149 |
echo "ERROR: \"perf\" program is not available." > /dev/stderr |
| 150 |
echo > /dev/stderr |
| 151 |
exit 1 |
| 152 |
fi |
| 153 |
|
| 154 |
if which curl > /dev/null; then |
| 155 |
: |
| 156 |
else |
| 157 |
echo > /dev/stderr |
| 158 |
echo "ERROR: \"curl\" program is not available." > /dev/stderr |
| 159 |
echo > /dev/stderr |
| 160 |
exit 1 |
| 161 |
fi |
| 162 |
|
| 163 |
if which du > /dev/null; then |
| 164 |
: |
| 165 |
else |
| 166 |
echo > /dev/stderr |
| 167 |
echo "ERROR: \"du\" program is not available." > /dev/stderr |
| 168 |
echo > /dev/stderr |
| 169 |
exit 1 |
| 170 |
fi |
| 171 |
|
| 172 |
if [ ! -e "$working_dir" ]; then |
| 173 |
echo > /dev/stderr |
| 174 |
echo "ERROR: \"$working_dir\" does not exist." > /dev/stderr |
| 175 |
echo > /dev/stderr |
| 176 |
exit 1 |
| 177 |
fi |
| 178 |
|
| 179 |
if [ ! -d "$working_dir" ]; then |
| 180 |
echo > /dev/stderr |
| 181 |
echo "ERROR: \"$working_dir\" is not a directory." > /dev/stderr |
| 182 |
echo > /dev/stderr |
| 183 |
exit 1 |
| 184 |
fi |
| 185 |
|
| 186 |
if [ ! -w "$working_dir" ]; then |
| 187 |
echo > /dev/stderr |
| 188 |
echo "ERROR: \"$working_dir\" is not writable." > /dev/stderr |
| 189 |
echo > /dev/stderr |
| 190 |
exit 1 |
| 191 |
fi |
| 192 |
|
| 193 |
coq_opam_packages_on_separate_lines=$(echo "$coq_opam_packages" | sed 's/ /\n/g') |
| 194 |
if [ $(echo "$coq_opam_packages_on_separate_lines" | wc -l) != $(echo "$coq_opam_packages_on_separate_lines" | sort | uniq | wc -l) ]; then |
| 195 |
echo "ERROR: The provided set of OPAM packages contains duplicates." |
| 196 |
exit 1 |
| 197 |
fi |
| 198 |
|
| 199 |
# -------------------------------------------------------------------------------- |
| 200 |
|
| 201 |
# Tell coqbot to update the initial comment, if we know which one to update |
| 202 |
function coqbot_update_comment() { |
| 203 |
is_done="$1" |
| 204 |
comment_body="$2" |
| 205 |
uninstallable_packages="$3" |
| 206 |
|
| 207 |
if [ ! -z "${coq_pr_number}" ]; then |
| 208 |
comment_text="" |
| 209 |
artifact_text="" |
| 210 |
|
| 211 |
if [ -z "${is_done}" ]; then |
| 212 |
comment_text="in progress, " |
| 213 |
artifact_text="eventually " |
| 214 |
else |
| 215 |
comment_text="" |
| 216 |
artifact_text="" |
| 217 |
fi |
| 218 |
comment_text="Benchmarking ${comment_text}log available [here](${CI_JOB_URL}) ([raw log here](${CI_JOB_URL}/raw)), artifacts ${artifact_text}available for [download](${CI_JOB_URL}/artifacts/download) and [browsing](${CI_JOB_URL}/artifacts/browse)" |
| 219 |
|
| 220 |
if [ ! -z "${comment_body}" ]; then |
| 221 |
comment_text="${comment_text}${nl}${start_code_block}${nl}${comment_body}${nl}${end_code_block}" |
| 222 |
fi |
| 223 |
|
| 224 |
if [ ! -z "${uninstallable_packages}" ]; then |
| 225 |
comment_text="${comment_text}${nl}The following packages failed to install: ${uninstallable_packages}" |
| 226 |
fi |
| 227 |
|
| 228 |
comment_text="${comment_text}${nl}${nl}<details><summary>Old Rocq version ${old_coq_commit}</summary>" |
| 229 |
comment_text="${comment_text}${nl}${nl}${start_code_block}${nl}$(git log -n 1 "${old_coq_commit}")${nl}${end_code_block}${nl}</details>" |
| 230 |
comment_text="${comment_text}${nl}${nl}<details><summary>New Rocq version ${new_coq_commit}</summary>" |
| 231 |
comment_text="${comment_text}${nl}${nl}${start_code_block}${nl}$(git log -n 1 "${new_coq_commit}")${nl}${end_code_block}${nl}</details>" |
| 232 |
comment_text="${comment_text}${nl}${nl}[Diff: ${bt}${old_coq_commit}..${new_coq_commit}${bt}](https://github.com/rocq-prover/rocq/compare/${old_coq_commit}..${new_coq_commit})" |
| 233 |
|
| 234 |
# if there's a comment id, we update the comment while we're |
| 235 |
# in progress; otherwise, we wait until the end to post a new |
| 236 |
# comment |
| 237 |
if [ ! -z "${coq_pr_comment_id}" ]; then |
| 238 |
# Tell coqbot to update the in-progress comment |
| 239 |
curl -X POST --data-binary "${coq_pr_number}${nl}${coq_pr_comment_id}${nl}${comment_text}" "${coqbot_url_prefix}/update-comment" |
| 240 |
elif [ ! -z "${is_done}" ]; then |
| 241 |
# Tell coqbot to post a new comment that we're done benchmarking |
| 242 |
curl -X POST --data-binary "${coq_pr_number}${nl}${comment_text}" "${coqbot_url_prefix}/new-comment" |
| 243 |
fi |
| 244 |
if [ ! -z "${is_done}" ]; then |
| 245 |
# Tell coqbot to remove the `needs: benchmarking` label |
| 246 |
curl -X POST --data-binary "${coq_pr_number}" "${coqbot_url_prefix}/benchmarking-done" |
| 247 |
fi |
| 248 |
fi |
| 249 |
} |
| 250 |
|
| 251 |
# initial update to the comment, to say that we're in progress |
| 252 |
coqbot_update_comment "" "" "" |
| 253 |
|
| 254 |
# -------------------------------------------------------------------------------- |
| 255 |
|
| 256 |
zulip_post="" |
| 257 |
if [[ $ZULIP_BENCH_BOT ]]; then |
| 258 |
pr_full=$(git log -n 1 --pretty=%s) |
| 259 |
pr_full=${pr_full#"[CI merge] PR #"} |
| 260 |
pr_num=${pr_full%%:*} |
| 261 |
pr_msg=${pr_full#*:} |
| 262 |
zulip_header="Bench at $CI_JOB_URL |
| 263 |
Testing [$pr_msg](https://github.com/rocq-prover/rocq/pull/$pr_num) |
| 264 |
On packages $coq_opam_packages |
| 265 |
" |
| 266 |
|
| 267 |
# 24008 is the "github notifications" stream |
| 268 |
resp=$(curl -sSX POST https://rocq-prover.zulipchat.com/api/v1/messages \ |
| 269 |
-u "$ZULIP_BENCH_BOT" \ |
| 270 |
--data-urlencode type=stream \ |
| 271 |
--data-urlencode to='240008' \ |
| 272 |
--data-urlencode subject='Bench Notifications' \ |
| 273 |
--data-urlencode content="$zulip_header") |
| 274 |
|
| 275 |
zulip_post=$(echo "$resp" | jq .id) |
| 276 |
case "$zulip_post" in |
| 277 |
''|*[!0-9]*) # not an int |
| 278 |
echo "Failed to post to zulip: $resp" |
| 279 |
zulip_post="" |
| 280 |
;; |
| 281 |
esac |
| 282 |
fi |
| 283 |
|
| 284 |
zulip_edit() { |
| 285 |
if ! [[ $zulip_post ]]; then return; fi |
| 286 |
ending=$1 |
| 287 |
if [[ $rendered_results ]]; then |
| 288 |
msg="$zulip_header |
| 289 |
|
| 290 |
~~~ |
| 291 |
$rendered_results |
| 292 |
~~~ |
| 293 |
|
| 294 |
$ending |
| 295 |
" |
| 296 |
else |
| 297 |
msg="$zulip_header |
| 298 |
|
| 299 |
$ending |
| 300 |
" |
| 301 |
fi |
| 302 |
curl -sSX PATCH https://rocq-prover.zulipchat.com/api/v1/messages/"$zulip_post" \ |
| 303 |
-u "$ZULIP_BENCH_BOT" \ |
| 304 |
--data-urlencode content="$msg" >/dev/null || echo "Failed to edit zulip post" >&2 |
| 305 |
} |
| 306 |
zulip_autofail() { |
| 307 |
code=$? |
| 308 |
com=$BASH_COMMAND |
| 309 |
zulip_edit "Failed '$com' with exit code $code." |
| 310 |
} |
| 311 |
if [[ $zulip_post ]]; then trap zulip_autofail ERR; fi |
| 312 |
|
| 313 |
# see https://github.com/rocq-prover/rocq/pull/15807 |
| 314 |
if [ "$(ulimit -s)" != "unlimited" ]; then |
| 315 |
ulimit -S -s $((2 * $(ulimit -s))) |
| 316 |
fi |
| 317 |
|
| 318 |
# Clone the indicated git-repository. |
| 319 |
|
| 320 |
coq_dir="$working_dir/coq" |
| 321 |
git clone -q "$new_coq_repository" "$coq_dir" |
| 322 |
cd "$coq_dir" |
| 323 |
git remote rename origin new_coq_repository |
| 324 |
git remote add old_coq_repository "$old_coq_repository" |
| 325 |
git fetch -q "$old_coq_repository" |
| 326 |
git checkout -q $new_coq_commit |
| 327 |
|
| 328 |
coq_opam_version=dev |
| 329 |
|
| 330 |
# -------------------------------------------------------------------------------- |
| 331 |
|
| 332 |
new_opam_root="$working_dir/opam.NEW" |
| 333 |
old_opam_root="$working_dir/opam.OLD" |
| 334 |
|
| 335 |
# -------------------------------------------------------------------------------- |
| 336 |
|
| 337 |
old_coq_opam_archive_dir="$working_dir/old_coq_opam_archive" |
| 338 |
git clone -q --depth 1 -b "$old_coq_opam_archive_git_branch" "$old_coq_opam_archive_git_uri" "$old_coq_opam_archive_dir" |
| 339 |
new_coq_opam_archive_dir="$working_dir/new_coq_opam_archive" |
| 340 |
git clone -q --depth 1 -b "$new_coq_opam_archive_git_branch" "$new_coq_opam_archive_git_uri" "$new_coq_opam_archive_dir" |
| 341 |
|
| 342 |
initial_opam_packages="num zarith ocamlfind dune yojson camlzip" |
| 343 |
|
| 344 |
# Create an opam root and install Rocq |
| 345 |
# $1 = root_name {ex: NEW / OLD} |
| 346 |
# $2 = compiler name |
| 347 |
# $3 = git hash of Rocq to be installed |
| 348 |
# $4 = directory of coq opam archive |
| 349 |
# $5 = use flambda if nonempty |
| 350 |
create_opam() { |
| 351 |
|
| 352 |
local RUNNER="$1" |
| 353 |
local OPAM_DIR="$working_dir/opam.$RUNNER" |
| 354 |
local OCAML_VER="$2" |
| 355 |
local COQ_HASH="$3" |
| 356 |
local COQ_VER="$4" |
| 357 |
local OPAM_COQ_DIR="$5" |
| 358 |
local OPAM_OVERRIDE_URLS="$6" |
| 359 |
local USE_FLAMBDA="$7" |
| 360 |
|
| 361 |
local OPAM_COMP=ocaml-base-compiler.$OCAML_VER |
| 362 |
|
| 363 |
export OPAMROOT="$OPAM_DIR" |
| 364 |
export COQ_RUNNER="$RUNNER" |
| 365 |
|
| 366 |
opam init --disable-sandboxing -qn -j "$number_of_processors" --bare |
| 367 |
# Allow beta compiler switches |
| 368 |
opam repo add -q --set-default beta https://github.com/ocaml/ocaml-beta-repository.git |
| 369 |
# Allow experimental compiler switches |
| 370 |
opam repo add -q --set-default ocaml-pr https://github.com/ejgallego/ocaml-pr-repository.git |
| 371 |
# Rest of default switches |
| 372 |
opam repo add -q --set-default iris-dev "https://gitlab.mpi-sws.org/FP/opam-dev.git" |
| 373 |
|
| 374 |
if [[ $USE_FLAMBDA = 1 ]]; |
| 375 |
then flambda=--packages=ocaml-variants.${OCAML_VER}+options,ocaml-option-flambda |
| 376 |
else flambda= |
| 377 |
fi |
| 378 |
|
| 379 |
opam switch create -qy -j "$number_of_processors" "ocaml-$RUNNER" "$OPAM_COMP" $flambda |
| 380 |
eval $(opam env) |
| 381 |
|
| 382 |
if [ ! -z "$BENCH_DEBUG" ]; then opam config list; fi |
| 383 |
|
| 384 |
opam repo add -q --this-switch coq-core-dev "$OPAM_COQ_DIR/core-dev" # For rocq-stdlib |
| 385 |
opam repo add -q --this-switch coq-extra-dev "$OPAM_COQ_DIR/extra-dev" |
| 386 |
opam repo add -q --this-switch coq-released "$OPAM_COQ_DIR/released" |
| 387 |
|
| 388 |
local override_package |
| 389 |
local url_or_package |
| 390 |
for url_or_package in $OPAM_OVERRIDE_URLS; do |
| 391 |
if [ "$override_package" ]; then |
| 392 |
echo "Setting source url for $override_package to $url_or_package in $RUNNER" |
| 393 |
# NB opam editor start seems to ignore -y but works with </dev/null |
| 394 |
OPAMEDITOR="echo 'url { src: \"$url_or_package\" }' >> " opam pin add -nye "$override_package" - </dev/null |
| 395 |
opam show "$override_package" --raw |
| 396 |
override_package= |
| 397 |
else |
| 398 |
override_package=$url_or_package |
| 399 |
fi |
| 400 |
done |
| 401 |
if [ "$override_package" ]; then |
| 402 |
>&2 echo "malformed opam_override_urls for $RUNNER (odd length)" |
| 403 |
zulip_edit "Bench failed: malformed opam_override_urls for $RUNNER (odd length)" |
| 404 |
exit 1 |
| 405 |
fi |
| 406 |
|
| 407 |
opam install -qy -j "$number_of_processors" $initial_opam_packages |
| 408 |
if [ ! -z "$BENCH_DEBUG" ]; then opam repo list; fi |
| 409 |
|
| 410 |
cd "$coq_dir" |
| 411 |
echo "$1_coq_commit = $COQ_HASH" |
| 412 |
|
| 413 |
echo "wrap-build-commands: [\"$program_path/wrapper.sh\"]" >> "$OPAM_DIR/config" |
| 414 |
|
| 415 |
git checkout -q $COQ_HASH |
| 416 |
COQ_HASH_LONG=$(git log --pretty=%H | head -n 1) |
| 417 |
|
| 418 |
echo "$1_coq_commit_long = $COQ_HASH_LONG" |
| 419 |
|
| 420 |
if [ ! -z "$coq_native" ]; then opam install coq-native rocq-native; fi |
| 421 |
|
| 422 |
} |
| 423 |
|
| 424 |
# Create an OPAM-root to which we will install the NEW version of Rocq. |
| 425 |
create_opam "NEW" "$new_ocaml_version" "$new_coq_commit" "$new_coq_version" \ |
| 426 |
"$new_coq_opam_archive_dir" "$new_opam_override_urls" "$new_ocaml_flambda" |
| 427 |
new_coq_commit_long="$COQ_HASH_LONG" |
| 428 |
|
| 429 |
# pre build needed helpers (needs an opam switch) |
| 430 |
dune build --root "$program_path/../.." -- dev/bench/render_results.exe dev/bench/render_line_results.exe rocq-devtools.install |
| 431 |
|
| 432 |
render_results=$(readlink -f "$program_path/../../_build/default/dev/bench/render_results.exe") |
| 433 |
render_line_results=$(readlink -f "$program_path/../../_build/default/dev/bench//render_line_results.exe") |
| 434 |
timelog2html=$(readlink -f "$program_path/../../_build/default/dev/bench/rocqtimelog2html.exe") |
| 435 |
|
| 436 |
# Create an OPAM-root to which we will install the OLD version of Rocq. |
| 437 |
create_opam "OLD" "$old_ocaml_version" "$old_coq_commit" "$old_coq_version" \ |
| 438 |
"$old_coq_opam_archive_dir" "$old_opam_override_urls" "$old_ocaml_flambda" |
| 439 |
old_coq_commit_long="$COQ_HASH_LONG" |
| 440 |
|
| 441 |
installable_coq_opam_packages="" |
| 442 |
|
| 443 |
zulip_edit "Opam setup, benching continues..." |
| 444 |
|
| 445 |
format_vosize() { |
| 446 |
old=$(stat -c%s $2) |
| 447 |
new=$(stat -c%s $3) |
| 448 |
diff=$((new - old)) |
| 449 |
diffpercent=$(((diff * 100) / $old)) |
| 450 |
echo "$1 $old $new $diff $diffpercent%" |
| 451 |
} |
| 452 |
|
| 453 |
# -------------------------------------------------------------------------------- |
| 454 |
# Measure the compilation times of the specified OPAM packages in both switches |
| 455 |
|
| 456 |
failed_packages= |
| 457 |
skipped_packages= |
| 458 |
|
| 459 |
# Generate per line timing info in devs that use coq_makefile |
| 460 |
export TIMING=1 |
| 461 |
export PROFILING=1 |
| 462 |
export ROCQ_PROFILE_COMPONENTS=command,parse_command,partac.perform |
| 463 |
|
| 464 |
# packages tied to the coq commit need to be pinned accordingly |
| 465 |
core_packages='rocq-runtime coq-core rocq-core coqide-server' |
| 466 |
|
| 467 |
for coq_opam_package in $core_packages $coq_opam_packages; do |
| 468 |
|
| 469 |
export COQ_OPAM_PACKAGE=$coq_opam_package |
| 470 |
is_core= |
| 471 |
for core in $core_packages; do |
| 472 |
if [ "$coq_opam_package" = "$core" ]; then is_core=1; fi |
| 473 |
done |
| 474 |
if [[ $is_core ]]; then |
| 475 |
: not getting info from opam repo |
| 476 |
else |
| 477 |
if [ ! -z "$BENCH_DEBUG" ]; then |
| 478 |
opam list |
| 479 |
opam show $coq_opam_package || { |
| 480 |
failed_packages="$failed_packages |
| 481 |
$coq_opam_package (unknown package)" |
| 482 |
continue |
| 483 |
} |
| 484 |
else |
| 485 |
# cause to skip with error if unknown package |
| 486 |
opam show $coq_opam_package >/dev/null || { |
| 487 |
failed_packages="$failed_packages |
| 488 |
$coq_opam_package (unknown package)" |
| 489 |
continue |
| 490 |
} |
| 491 |
fi |
| 492 |
fi |
| 493 |
echo "coq_opam_package = $coq_opam_package" |
| 494 |
|
| 495 |
for RUNNER in NEW OLD; do |
| 496 |
|
| 497 |
export COQ_RUNNER=$RUNNER |
| 498 |
|
| 499 |
# perform measurements for the NEW/OLD commit (provided by the user) |
| 500 |
if [ $RUNNER = "NEW" ]; then |
| 501 |
export OPAMROOT="$new_opam_root" |
| 502 |
COQ_HASH=$new_coq_commit_long |
| 503 |
echo "Testing NEW commit: $(date)" |
| 504 |
else |
| 505 |
export OPAMROOT="$old_opam_root" |
| 506 |
COQ_HASH=$old_coq_commit_long |
| 507 |
echo "Testing OLD commit: $(date)" |
| 508 |
fi |
| 509 |
|
| 510 |
git checkout -q $COQ_HASH |
| 511 |
|
| 512 |
if { [ "$coq_opam_package" = rocq-core ] || [ "$coq_opam_package" = rocq-runtime ]; } \ |
| 513 |
&& ! [ -e $coq_opam_package.opam ]; then |
| 514 |
echo "Skipping $coq_opam_package for $RUNNER" |
| 515 |
continue 2 |
| 516 |
fi |
| 517 |
|
| 518 |
if [ -e "$coq_opam_package.opam" ]; then |
| 519 |
local_opam_dir=. |
| 520 |
elif [ -e "stdlib/$coq_opam_package.opam" ]; then |
| 521 |
local_opam_dir=stdlib |
| 522 |
else |
| 523 |
local_opam_dir= |
| 524 |
fi |
| 525 |
if [[ $local_opam_dir ]]; then |
| 526 |
opam pin add -ny "$coq_opam_package.dev" -k path $local_opam_dir |
| 527 |
fi |
| 528 |
|
| 529 |
eval $(opam env) |
| 530 |
|
| 531 |
# If a given OPAM-package was already installed (as a |
| 532 |
# dependency of some OPAM-package that we have benchmarked |
| 533 |
# before), remove it. |
| 534 |
opam uninstall -q $coq_opam_package >/dev/null 2>&1 |
| 535 |
|
| 536 |
# '∗' is a unicode star used by opam for packags to be installed |
| 537 |
for dep in $(opam install --show-actions "$coq_opam_package" | grep -o '∗\s*[^ ]*' | sed 's/∗\s*//g'); do |
| 538 |
# show-actions will print transitive deps |
| 539 |
# so we don't need to look at the skipped_packages |
| 540 |
if echo "$failed_packages" | grep -q "^$dep "; then |
| 541 |
skipped_packages="$skipped_packages |
| 542 |
$coq_opam_package (dependency $dep failed)" |
| 543 |
continue 3 |
| 544 |
fi |
| 545 |
done |
| 546 |
|
| 547 |
opam install $coq_opam_package -v -b -j "$number_of_processors" --deps-only -y \ |
| 548 |
3>$log_dir/$coq_opam_package.$RUNNER.opam_install.deps_only.stdout.log 1>&3 \ |
| 549 |
4>$log_dir/$coq_opam_package.$RUNNER.opam_install.deps_only.stderr.log 2>&4 || { |
| 550 |
failed_packages="$failed_packages |
| 551 |
$coq_opam_package (dependency install failed in $RUNNER)" |
| 552 |
continue 2 |
| 553 |
} |
| 554 |
|
| 555 |
if [ ! -z "$BENCH_DEBUG" ]; then ls -l $working_dir; fi |
| 556 |
|
| 557 |
for iteration in $(seq $num_of_iterations); do |
| 558 |
export COQ_ITERATION=$iteration |
| 559 |
_RES=0 |
| 560 |
timeout "$timeout" opam install -y -v -b -j 1 $coq_opam_package \ |
| 561 |
3>$log_dir/$coq_opam_package.$RUNNER.opam_install.$iteration.stdout.log 1>&3 \ |
| 562 |
4>$log_dir/$coq_opam_package.$RUNNER.opam_install.$iteration.stderr.log 2>&4 || \ |
| 563 |
_RES=$? |
| 564 |
if [ $_RES = 0 ]; |
| 565 |
then |
| 566 |
echo $_RES > $log_dir/$coq_opam_package.$RUNNER.opam_install.$iteration.exit_status |
| 567 |
# "opam install" was successful. |
| 568 |
|
| 569 |
# Remove the benchmarked OPAM-package, unless this is the |
| 570 |
# very last iteration (we want to keep this OPAM-package |
| 571 |
# because other OPAM-packages we will benchmark later |
| 572 |
# might depend on it --- it would be a waste of time to |
| 573 |
# remove it now just to install it later) |
| 574 |
if [ $iteration != $num_of_iterations ]; then |
| 575 |
opam uninstall -q $coq_opam_package |
| 576 |
fi |
| 577 |
else |
| 578 |
# "opam install" failed. |
| 579 |
echo $_RES > $log_dir/$coq_opam_package.$RUNNER.opam_install.$iteration.exit_status |
| 580 |
failed_packages="$failed_packages |
| 581 |
$coq_opam_package (in $RUNNER)" |
| 582 |
continue 3 |
| 583 |
fi |
| 584 |
done |
| 585 |
|
| 586 |
# avoid opam downgrading rocq if some package has weird constraints |
| 587 |
# there is no "opam switch add-invariant" so we do this sed instead, |
| 588 |
# cf https://github.com/ocaml/opam/issues/6269 |
| 589 |
if [ "$coq_opam_package" = "rocq-runtime" ]; then |
| 590 |
opam switch set-invariant --formula \ |
| 591 |
"$(opam switch invariant | sed 's/]/ \"'"$coq_opam_package"'\"]/')" |
| 592 |
fi |
| 593 |
done |
| 594 |
|
| 595 |
case $coq_opam_package in |
| 596 |
coqide-server|coq) |
| 597 |
# don't render results for these |
| 598 |
;; |
| 599 |
*) |
| 600 |
installable_coq_opam_packages="$installable_coq_opam_packages $coq_opam_package" |
| 601 |
esac |
| 602 |
|
| 603 |
# -------------------------------------------------------------- |
| 604 |
cat $log_dir/$coq_opam_package.$RUNNER.1.*.time || true |
| 605 |
cat $log_dir/$coq_opam_package.$RUNNER.1.*.perf || true |
| 606 |
|
| 607 |
# Print the intermediate results after we finish benchmarking each OPAM package |
| 608 |
if [ "$coq_opam_package" = "$(echo $coq_opam_packages | sed 's/ /\n/g' | tail -n 1)" ]; then |
| 609 |
|
| 610 |
# It does not make sense to print the intermediate results when |
| 611 |
# we finished bechmarking the very last OPAM package because the |
| 612 |
# next thing will do is that we will print the final results. |
| 613 |
# It would look lame to print the same table twice. |
| 614 |
: |
| 615 |
else |
| 616 |
|
| 617 |
echo "DEBUG: $render_results "$log_dir" $num_of_iterations 1 user_time_pdiff $installable_coq_opam_packages" |
| 618 |
rendered_results="$($render_results "$log_dir" $num_of_iterations 1 user_time_pdiff $installable_coq_opam_packages)" |
| 619 |
echo "${rendered_results}" |
| 620 |
# update the comment |
| 621 |
coqbot_update_comment "" "${rendered_results}" "" |
| 622 |
msg="Benching continues ($coq_opam_package done)..." |
| 623 |
if [ -n "$failed_packages" ]; then |
| 624 |
msg="$msg |
| 625 |
Failed: $failed_packages |
| 626 |
$skipped_packages" |
| 627 |
fi |
| 628 |
zulip_edit "$msg" |
| 629 |
fi |
| 630 |
|
| 631 |
# N.B. Not all packages end in .dev, e.g., coq-lambda-rust uses .dev.timestamp. |
| 632 |
# So we use a wildcard to catch such packages. |
| 633 |
coq_opam_package_nover=${coq_opam_package%%.*} |
| 634 |
new_base_path=$(echo "$new_opam_root/ocaml-NEW/.opam-switch/build/$coq_opam_package_nover".*/) |
| 635 |
old_base_path=$(echo "$old_opam_root/ocaml-OLD/.opam-switch/build/$coq_opam_package_nover".*/) |
| 636 |
|
| 637 |
# Generate per-file comparison |
| 638 |
for iteration in $(seq $num_of_iterations); do |
| 639 |
# opam logs prefix the printing with "- " so remove that |
| 640 |
# remove the base path for nicer printing and so the script can identify common files |
| 641 |
"$program_path"/../../tools/make-both-time-files.py --real \ |
| 642 |
<(sed -e 's/^- //' -e "s:$new_base_path::" "$log_dir/$coq_opam_package.NEW.opam_install.$iteration.stdout.log") \ |
| 643 |
<(sed -e 's/^- //' -e "s:$old_base_path::" "$log_dir/$coq_opam_package.OLD.opam_install.$iteration.stdout.log") \ |
| 644 |
> "$log_dir/$coq_opam_package.BOTH.perfile_timings.$iteration.log" |
| 645 |
done |
| 646 |
|
| 647 |
# Generate HTML report for LAST run |
| 648 |
|
| 649 |
for vo in $(cd $new_base_path/; find . -name '*.vo'); do |
| 650 |
if [ -e $old_base_path/$vo ]; then |
| 651 |
format_vosize "$coq_opam_package/$vo" "$old_base_path/$vo" "$new_base_path/$vo" >> "$log_dir/vosize.log" |
| 652 |
fi |
| 653 |
|
| 654 |
# use profile if it exists, otherwise timing |
| 655 |
# NB: timelog2html sometimes randomly fails |
| 656 |
old_data= |
| 657 |
new_data= |
| 658 |
if [ -e "$old_base_path/$vo.prof.json.gz" ]; then |
| 659 |
old_data="$old_base_path/$vo.prof.json.gz" |
| 660 |
elif [ -e "$old_base_path/${vo%%o}.timing" ]; then |
| 661 |
old_data="$old_base_path/${vo%%o}.timing" |
| 662 |
fi |
| 663 |
if [ -e "$new_base_path/$vo.prof.json.gz" ]; then |
| 664 |
new_data="$new_base_path/$vo.prof.json.gz" |
| 665 |
elif [ -e "$new_base_path/${vo%%o}.timing" ]; then |
| 666 |
new_data="$new_base_path/${vo%%o}.timing" |
| 667 |
fi |
| 668 |
|
| 669 |
if [ "$old_data" ] && [ "$new_data" ]; then |
| 670 |
mkdir -p "$working_dir/html/$coq_opam_package/$(dirname "$vo")/" |
| 671 |
$timelog2html \ |
| 672 |
"-o" "$working_dir/html/$coq_opam_package/${vo%%o}.html" \ |
| 673 |
"-raw-o" "$working_dir/html/$coq_opam_package/${vo%%o}.rocq-timediff" \ |
| 674 |
"$new_base_path/${vo%%o}" \ |
| 675 |
"$old_data" \ |
| 676 |
"$new_data" \ |
| 677 |
|| echo "Failed (code $?): timelog2html for $vo on $old_data $new_data" |
| 678 |
fi |
| 679 |
done |
| 680 |
done |
| 681 |
|
| 682 |
# Since we do not upload all files, store a list of the files |
| 683 |
# available so that if we at some point want to tweak which files we |
| 684 |
# upload, we'll know which ones are available for upload |
| 685 |
du -ha "$working_dir" > "$working_dir/files.listing" |
| 686 |
|
| 687 |
# The following directories in $working_dir are no longer used: |
| 688 |
# |
| 689 |
# - coq, opam.OLD, opam.NEW |
| 690 |
|
| 691 |
# Measured data for each `$coq_opam_package`, `$iteration`, `status \in {NEW,OLD}`: |
| 692 |
# |
| 693 |
# - $working_dir/$coq_opam_package.$status.$iteration.time |
| 694 |
# => output of /usr/bin/time --format="%U" ... |
| 695 |
# |
| 696 |
# - $working_dir/$coq_opam_package.NEW.$iteration.perf |
| 697 |
# => output of perf stat -e instructions:u,cycles:u ... |
| 698 |
# |
| 699 |
# The next script processes all these files and prints results in a table. |
| 700 |
|
| 701 |
# Generate per-file comparison for everything at once |
| 702 |
new_base_path=$new_opam_root/ocaml-NEW/.opam-switch/build/ |
| 703 |
old_base_path=$old_opam_root/ocaml-OLD/.opam-switch/build/ |
| 704 |
for iteration in $(seq $num_of_iterations); do |
| 705 |
"$program_path"/../../tools/make-both-time-files.py --real \ |
| 706 |
<(sed -e 's/^- //' -e "s:$new_base_path::" "$log_dir/"*".NEW.opam_install.$iteration.stdout.log") \ |
| 707 |
<(sed -e 's/^- //' -e "s:$old_base_path::" "$log_dir/"*".OLD.opam_install.$iteration.stdout.log") \ |
| 708 |
> "$log_dir/ALL.BOTH.perfile_timings.$iteration.log" |
| 709 |
done |
| 710 |
|
| 711 |
# timings data |
| 712 |
timings=$working_dir/timings |
| 713 |
mkdir -p $timings |
| 714 |
|
| 715 |
# Print line by line slow downs and speed ups |
| 716 |
if [ -d "$working_dir/html" ]; then # might not exist if all jobs failed |
| 717 |
cd "$working_dir/html" |
| 718 |
$render_line_results |
| 719 |
# Move line timing files to timings folder (they will become artifacts) |
| 720 |
mv fast_table slow_table timings_table $timings |
| 721 |
|
| 722 |
# html tables don't get generated if the bench is run locally ie without CI variables |
| 723 |
for f in fast_table.html slow_table.html timings_table.html; do |
| 724 |
if [ -f "$f" ]; then mv "$f" $timings; fi |
| 725 |
done |
| 726 |
fi |
| 727 |
|
| 728 |
echo "INFO: workspace = ${CI_JOB_URL:-.}/artifacts/browse/${bench_dirname}" |
| 729 |
|
| 730 |
# Print the final results. |
| 731 |
if [ -z "$installable_coq_opam_packages" ]; then |
| 732 |
# Tell the user that none of the OPAM-package(s) the user provided |
| 733 |
# /are installable. |
| 734 |
printf "\n\nINFO: failed to install: $coq_opam_packages" |
| 735 |
coqbot_update_comment "done" "" "$coq_opam_packages" |
| 736 |
exit 1 |
| 737 |
fi |
| 738 |
|
| 739 |
echo "DEBUG: $render_results $log_dir $num_of_iterations 1 user_time_pdiff $installable_coq_opam_packages" |
| 740 |
rendered_results="$($render_results "$log_dir" $num_of_iterations 1 user_time_pdiff $installable_coq_opam_packages)" |
| 741 |
echo "${rendered_results}" |
| 742 |
echo "${rendered_results}" > $timings/bench_summary |
| 743 |
|
| 744 |
echo "INFO: per line timing: ${CI_JOB_URL:-.}/artifacts/browse/${bench_dirname}/html/" |
| 745 |
|
| 746 |
cd "$coq_dir" |
| 747 |
echo INFO: Old Rocq version |
| 748 |
git log -n 1 "$old_coq_commit" |
| 749 |
echo INFO: New Rocq version |
| 750 |
git log -n 1 "$new_coq_commit" |
| 751 |
|
| 752 |
if [ -n "$failed_packages" ]; then |
| 753 |
not_installable_coq_opam_packages=$failed_packages |
| 754 |
if [ -n "$skipped_packages" ]; then |
| 755 |
not_installable_coq_opam_packages="$not_installable_coq_opam_packages |
| 756 |
$skipped_packages" |
| 757 |
fi |
| 758 |
else # in case the failed package detection is bugged |
| 759 |
not_installable_coq_opam_packages=$(comm -23 <(echo $coq_opam_packages | sed 's/ /\n/g' | sort | uniq) <(echo $installable_coq_opam_packages | sed 's/ /\n/g' | sort | uniq) | sed 's/\t//g') |
| 760 |
fi |
| 761 |
|
| 762 |
coqbot_update_comment "done" "${rendered_results}" "${not_installable_coq_opam_packages}" |
| 763 |
|
| 764 |
touch $timings/bench_failures |
| 765 |
if [ -n "$not_installable_coq_opam_packages" ]; then |
| 766 |
# Tell the user that some of the provided OPAM-package(s) |
| 767 |
# is/are not installable. |
| 768 |
printf '\n\nINFO: failed to install %s\n' "$not_installable_coq_opam_packages" | tee $timings/bench_failures |
| 769 |
zulip_edit "Bench complete, failed to install packages: |
| 770 |
$not_installable_coq_opam_packages" |
| 771 |
exit 1 |
| 772 |
fi |
| 773 |
|
| 774 |
zulip_edit "Bench complete: all packages successfully installed." |