11
11
import subprocess as sp
12
12
import sys
13
13
from dataclasses import dataclass
14
- from glob import glob , iglob
14
+ from glob import glob
15
15
from inspect import cleandoc
16
16
from os import getenv
17
17
from pathlib import Path
38
38
39
39
Note that `--extract` will overwrite files in `iai-home`.
40
40
41
- check-regressions [--home iai-home] [--allow-pr-override pr_number]
42
- Check `iai-home` (or `iai-home` if unspecified) for `summary.json`
43
- files and see if there are any regressions. This is used as a workaround
44
- for `iai-callgrind` not exiting with error status; see
45
- <https://github.com/iai-callgrind/iai-callgrind/issues/337>.
46
-
47
- If `--allow-pr-override` is specified, the regression check will not exit
48
- with failure if any line in the PR starts with `allow-regressions`.
41
+ handle-bench-regressions PR_NUMBER
42
+ Exit with success if the pull request contains a line starting with
43
+ `ci: allow-regressions`, indicating that regressions in benchmarks should
44
+ be accepted. Otherwise, exit 1.
49
45
"""
50
46
)
51
47
@@ -365,64 +361,22 @@ def locate_baseline(flags: list[str]) -> None:
365
361
eprint ("baseline extracted successfully" )
366
362
367
363
368
- def check_iai_regressions (args : list [str ]):
369
- """Find regressions in iai summary.json files, exit with failure if any are
370
- found.
371
- """
372
-
373
- iai_home_str = "iai-home"
374
- pr_number = None
375
-
376
- while len (args ) > 0 :
377
- match args :
378
- case ["--home" , home , * rest ]:
379
- iai_home_str = home
380
- args = rest
381
- case ["--allow-pr-override" , pr_num , * rest ]:
382
- pr_number = pr_num
383
- args = rest
384
- case _:
385
- eprint (USAGE )
386
- exit (1 )
387
-
388
- iai_home = Path (iai_home_str )
389
-
390
- found_summaries = False
391
- regressions : list [dict ] = []
392
- for summary_path in iglob ("**/summary.json" , root_dir = iai_home , recursive = True ):
393
- found_summaries = True
394
- with open (iai_home / summary_path , "r" ) as f :
395
- summary = json .load (f )
396
-
397
- summary_regs = []
398
- run = summary ["callgrind_summary" ]["callgrind_run" ]
399
- fname = summary ["function_name" ]
400
- id = summary ["id" ]
401
- name_entry = {"name" : f"{ fname } .{ id } " }
402
-
403
- for segment in run ["segments" ]:
404
- summary_regs .extend (segment ["regressions" ])
364
+ def handle_bench_regressions (args : list [str ]):
365
+ """Exit with error unless the PR message contains an ignore directive."""
405
366
406
- summary_regs .extend (run ["total" ]["regressions" ])
407
-
408
- regressions .extend (name_entry | reg for reg in summary_regs )
409
-
410
- if not found_summaries :
411
- eprint (f"did not find any summary.json files within { iai_home } " )
412
- exit (1 )
367
+ match args :
368
+ case [pr_number ]:
369
+ pr_number = pr_number
370
+ case _:
371
+ eprint (USAGE )
372
+ exit (1 )
413
373
414
- if len (regressions ) == 0 :
415
- eprint ("No regressions found" )
374
+ pr = PrInfo .load (pr_number )
375
+ if pr .contains_directive (REGRESSION_DIRECTIVE ):
376
+ eprint ("PR allows regressions" )
416
377
return
417
378
418
- eprint ("Found regressions:" , json .dumps (regressions , indent = 4 ))
419
-
420
- if pr_number is not None :
421
- pr = PrInfo .load (pr_number )
422
- if pr .contains_directive (REGRESSION_DIRECTIVE ):
423
- eprint ("PR allows regressions, returning" )
424
- return
425
-
379
+ eprint ("Regressions were found; benchmark failed" )
426
380
exit (1 )
427
381
428
382
@@ -433,8 +387,8 @@ def main():
433
387
ctx .emit_workflow_output ()
434
388
case ["locate-baseline" , * flags ]:
435
389
locate_baseline (flags )
436
- case ["check -regressions" , * args ]:
437
- check_iai_regressions (args )
390
+ case ["handle-bench -regressions" , * args ]:
391
+ handle_bench_regressions (args )
438
392
case ["--help" | "-h" ]:
439
393
print (USAGE )
440
394
exit ()
0 commit comments