16
16
LOGGER = logging .getLogger (__name__ )
17
17
18
18
19
+ def cargo_bench ():
20
+ """Executes all benchmarks by running "cargo bench --no-run", finding the executables, and running them pinned to some CPU"""
21
+ # Passing --message-format json to cargo tells it to print its log in a json format. At the end, instead of the
22
+ # usual "placed executable <...> at <...>" we'll get a json object with an 'executable' key, from which we
23
+ # extract the path to the compiled benchmark binary.
24
+ _ , stdout , _ = cargo (
25
+ "bench" ,
26
+ f"--all --quiet --target { platform .machine ()} -unknown-linux-musl --message-format json --no-run" ,
27
+ )
28
+
29
+ executables = []
30
+ for line in stdout .split ("\n " ):
31
+ if line :
32
+ msg = json .loads (line )
33
+ executable = msg .get ("executable" )
34
+ if executable :
35
+ executables .append (executable )
36
+
37
+ output = ""
38
+
39
+ for executable in executables :
40
+ output += utils .run_cmd (
41
+ f"CARGO_TARGET_DIR=../build/cargo_target taskset -c 1 { executable } --bench"
42
+ ).stdout
43
+
44
+ return output
45
+
46
+
19
47
@pytest .mark .no_block_pr
20
48
@pytest .mark .timeout (600 )
21
49
def test_no_regression_relative_to_target_branch ():
@@ -27,14 +55,12 @@ def test_no_regression_relative_to_target_branch():
27
55
# the test was originally executed
28
56
_ , pr_head_commit_sha , _ = utils .run_cmd ("git rev-parse HEAD" )
29
57
utils .run_cmd (f"git switch { TARGET_BRANCH } " )
30
- cargo ( "bench" , f"--all --quiet --target { platform . machine () } -unknown-linux-musl" )
58
+ cargo_bench ( )
31
59
32
60
# Switch back to pull request, and run benchmarks again. Criterion will automatically notice that
33
61
# data from a previous run exists, and do a comparison
34
62
utils .run_cmd (f"git checkout { pr_head_commit_sha } " )
35
- _ , criterion_output , _ = cargo (
36
- "bench" , f"--all --quiet --target { platform .machine ()} -unknown-linux-musl"
37
- )
63
+ criterion_output = cargo_bench ()
38
64
39
65
# Criterion separates reports for benchmarks by two newlines. We filter and print the ones
40
66
# that contain the string 'Performance has regression.', which criterion uses to indicate a regression
0 commit comments