Skip to content

Commit 64c67f8

Browse files
nmattiabasvandijk
andauthored
feat: add support for CRITERION_HOME (#7979)
This introduces a new CLI argument `--criterion-home` that we intercept and use to set `CRITERION_HOME` for the bench runner. See comment in code for details. This allows us to specify the criterion root (home) where we start looking for bench dirs, in order to avoid false positives from `bazel-out/`. --------- Co-authored-by: Bas van Dijk <[email protected]>
1 parent 4032584 commit 64c67f8

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

.github/workflows/schedule-rust-bench.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ jobs:
6060
run: |
6161
echo -e "\e[34mRunning rust benchmarks on dedicated machine fr1-spm15!\e[0m"
6262
63+
CRITERION_HOME=$(mktemp -d)
64+
trap "rm -rf $CRITERION_HOME" INT TERM EXIT
65+
6366
while IFS= read -r tgt; do
64-
bazel run "$tgt"
67+
bazel run "$tgt" -- --criterion-home "$CRITERION_HOME"
6568
done < <(bazel query "attr(tags, 'rust_bench', ${{ matrix.target }})")
6669
6770
while IFS= read -r bench_dir; do
@@ -82,6 +85,6 @@ jobs:
8285
>report.json
8386
curl --fail --retry 2 -sS -o /dev/null -X POST -H 'Content-Type: application/json' --data @report.json \
8487
"https://elasticsearch.testnet.dfinity.network/ci-performance-test/_doc"
85-
done < <(find -L ./bazel-out -type d -path '*/new')
88+
done < <(find -L "$CRITERION_HOME" -type d -path '*/new')
8689
8790
echo -e "\e[34mRust benchmarks on dedicated machine fr1-spm15 finished.\e[0m"

bazel/generic_rust_bench.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
set -euo pipefail
44

5+
# criterion supports specifying a "home" where it places its benchmark result tree.
6+
# at the time of writing, our bazel version (.bazelversion) is outdated and sh_binary
7+
# does not support `env_inherit` so add (or rather intercept) a new CLI argument
8+
# `--criterion-home` which we convert into `CRITERION_HOME`, which is read by
9+
# criterion.rs.
10+
#
11+
# https://github.com/criterion-rs/criterion.rs/blob/950c3b727a09d10067ea686e2ac6f1f23569168f/src/lib.rs#L142-L142
12+
13+
# store passthru args
14+
args=()
15+
while [[ $# -gt 0 ]]; do
16+
case $1 in
17+
--criterion-home)
18+
shift
19+
export CRITERION_HOME="$1"
20+
;;
21+
*)
22+
# passthru
23+
args+=("$1")
24+
shift
25+
;;
26+
esac
27+
done
28+
529
# When Cargo runs benchmarks, it passes the --bench or --test command-line arguments to
630
# the benchmark executables. Criterion.rs looks for these arguments and tries to either
731
# run benchmarks or run in test mode. In particular, when you run cargo test --benches
@@ -11,7 +35,7 @@ set -euo pipefail
1135
# present, or when --bench and --test are both present.
1236
#
1337
# https://bheisler.github.io/criterion.rs/book/faq.html#when-i-run-benchmark-executables-directly-without-using-cargo-they-just-print-success-why
14-
CMD="${BAZEL_DEFS_BENCH_PREFIX}${BAZEL_DEFS_BENCH_BIN} --bench $@"
38+
CMD="${BAZEL_DEFS_BENCH_PREFIX}${BAZEL_DEFS_BENCH_BIN} --bench ${args[@]}"
1539

1640
echo "running ${CMD}"
1741
${CMD}

0 commit comments

Comments
 (0)