Skip to content

Commit 25d930d

Browse files
committed
shorten logging
1 parent 4a3e296 commit 25d930d

File tree

2 files changed

+50
-63
lines changed

2 files changed

+50
-63
lines changed

devops/actions/run-tests/benchmark/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ runs:
170170
--results-dir "./llvm-ci-perf-results/results/" \
171171
--regression-filter '^[a-z_]+_sycl ' \
172172
--verbose \
173-
--produce-github-summary \
173+
--produce-github-summary "github_summary.md" \
174174
${{ inputs.dry_run == 'true' && '--dry-run' || '' }} \
175175

176176
echo "-----"

devops/scripts/benchmarks/compare.py

Lines changed: 49 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,6 @@ class BenchmarkHistoricAverage:
4646
# TODO Ensure ONEAPI_DEVICE_SELECTOR? GPU name itself?
4747

4848

49-
class OutputFile:
50-
"""
51-
Represents a text file to output, but only output the file when manually
52-
specified.
53-
"""
54-
55-
def __init__(self, output_path: str):
56-
self.output_path = output_path
57-
self.output_content = []
58-
59-
def write_file(self):
60-
with open(self.output_path, "w") as f:
61-
f.write("\n".join(self.output_content))
62-
63-
def println(self, text: str):
64-
self.output_content.append(text)
65-
66-
6749
class Compare:
6850
"""Class containing logic for comparisons between results"""
6951

@@ -358,18 +340,25 @@ def to_hist(
358340
parser_avg.add_argument(
359341
"--regression-filter",
360342
type=str,
361-
help="If provided, only regressions matching provided regex will cause exit status 1.",
343+
help="If provided, only regressions in tests matching provided regex will cause exit status 1.",
362344
default=None,
363345
)
346+
parser_avg.add_argument(
347+
"--regression-filter-type",
348+
type=str,
349+
help="Name to use in logging for tests that fall within the filter defined by --regression-filter; i.e. if --regression-filter filters for SYCL benchmarks, --regression-filter-type could be 'SYCL'.",
350+
default="filtered",
351+
)
364352
parser_avg.add_argument(
365353
"--dry-run",
366354
action="store_true",
367355
help="Do not return error upon regressions.",
368356
)
369357
parser_avg.add_argument(
370358
"--produce-github-summary",
371-
action="store_true",
372-
help="Produce a github CI summary file.",
359+
type=str,
360+
help="Create a github CI summary file using the provided filename",
361+
default="",
373362
)
374363

375364
args = parser.parse_args()
@@ -388,14 +377,24 @@ def to_hist(
388377
args.avg_type, args.name, args.compare_file, args.results_dir, args.cutoff
389378
)
390379

380+
# Initialize github summary variables:
381+
if args.produce_github_summary:
382+
gh_summary = []
383+
384+
filter_type_capitalized = (
385+
args.regression_filter_type[0].upper() + args.regression_filter_type[1:]
386+
)
387+
388+
def write_summary_to_file(summary: list[str]):
389+
with open(args.produce_github_summary, 'w') as f:
390+
f.write("\n".join(summary))
391+
392+
391393
# Not all regressions are of concern: if a filter is provided, filter
392394
# regressions using filter
393395
regressions_ignored = []
394396
regressions_of_concern = []
395397
if args.regression_filter is not None:
396-
if args.produce_github_summary:
397-
gh_summary = OutputFile("github_summary.md")
398-
399398
filter_pattern = re.compile(args.regression_filter)
400399
for test in regressions:
401400
if filter_pattern.search(test["name"]):
@@ -404,7 +403,7 @@ def to_hist(
404403
regressions_ignored.append(test)
405404

406405
def print_regression(entry: dict, is_warning: bool = False):
407-
"""Print an entry outputted from Compare.to_hist
406+
"""Print an entry outputted from Compare.to_hist[github_summary.md")
408407
409408
Args:
410409
entry (dict): The entry to print
@@ -417,80 +416,68 @@ def print_regression(entry: dict, is_warning: bool = False):
417416
log_func(f"-- Delta: {entry['delta']}")
418417
log_func("")
419418
if args.produce_github_summary:
420-
gh_summary.println(f"#### {entry['name']}:")
421-
gh_summary.println(
419+
gh_summary.append(f"#### {entry['name']}:")
420+
gh_summary.append(
422421
f"- Historic {entry['avg_type']}: {entry['hist_avg']}"
423422
)
424-
gh_summary.println(f"- Run result: {entry['value']}")
425-
gh_summary.println(f"- Delta: {entry['delta']}")
426-
gh_summary.println("")
423+
gh_summary.append(f"- Run result: {entry['value']}")
424+
gh_summary.append(f"- Delta: {round(entry['delta']*100, 2)}% ({entry['delta']})")
425+
gh_summary.append("")
427426

428427
if improvements:
429428
log.info("#")
430429
log.info("# Improvements:")
431430
log.info("#")
432431
if args.produce_github_summary:
433-
gh_summary.println("### Improvements")
434-
gh_summary.println(
432+
gh_summary.append(f"### Improvements")
433+
gh_summary.append(
435434
f"<details><summary>{len(improvements)} improved tests:</summary>"
436435
)
437-
gh_summary.println("")
436+
gh_summary.append("")
438437
for test in improvements:
439438
print_regression(test)
440439
if args.produce_github_summary:
441-
gh_summary.println("</details>")
442-
gh_summary.println("")
440+
gh_summary.append("</details>")
441+
gh_summary.append("")
443442
if regressions_ignored:
444443
log.info("#")
445-
log.info("# Regressions (filtered out by regression-filter):")
444+
log.info("# Regressions (filtered out by --regression-filter):")
446445
log.info("#")
447446
if args.produce_github_summary:
448-
gh_summary.println("### Regressions")
449-
gh_summary.println(
450-
f"<details><summary>{len(regressions_ignored)} non CI-failing regressions:</summary>"
447+
gh_summary.append(f"### Non-{filter_type_capitalized} Regressions")
448+
gh_summary.append(
449+
f"<details><summary>{len(regressions_ignored)} non-{args.regression_filter_type} regressions:</summary>"
451450
)
452-
gh_summary.println("")
451+
gh_summary.append("")
453452
for test in regressions_ignored:
454453
print_regression(test)
455454
if args.produce_github_summary:
456-
gh_summary.println("</details>")
457-
gh_summary.println("")
455+
gh_summary.append("</details>")
456+
gh_summary.append("")
458457
if regressions_of_concern:
459458
log.warning("#")
460459
log.warning("# Regressions:")
461460
log.warning("#")
462461
if args.produce_github_summary:
463-
gh_summary.println("### SYCL-Specific Regressions")
464-
gh_summary.println(
465-
"Regressions pertaining to non-experimental "
466-
"SYCL benchmarks. These regressions warrant "
467-
"a CI failure: "
468-
)
469-
gh_summary.println(
470-
f"<details><summary>{len(regressions_of_concern)} CI-failing regressions:</summary>"
462+
gh_summary.append(f"### {filter_type_capitalized} Regressions")
463+
gh_summary.append(
464+
f"{len(regressions_of_concern)} {args.regression_filter_type} regressions. These regressions warrant a CI failure:"
471465
)
472-
gh_summary.println("")
466+
gh_summary.append("")
473467
for test in regressions_of_concern:
474468
print_regression(test, is_warning=True)
475469
if args.produce_github_summary:
476-
gh_summary.println("</details>")
477-
gh_summary.println("")
470+
gh_summary.append("")
478471

479472
if not args.dry_run:
480473
if args.produce_github_summary:
481-
gh_summary.println("### Failed benchmarks:")
482-
gh_summary.println("")
483-
for test in regressions_of_concern:
484-
gh_summary.println(
485-
f"- {test['name']}: Delta {round(test['delta']*100, 2)}%"
486-
)
487-
gh_summary.write_file()
474+
write_summary_to_file(gh_summary)
488475
exit(1) # Exit 1 to trigger github test failure
489476

490477
log.info("No unexpected regressions found!")
491478
if args.produce_github_summary:
492-
gh_summary.println("No unexpected regressions found!")
493-
gh_summary.write_file()
479+
gh_summary.append("No unexpected regressions found!")
480+
write_summary_to_file(gh_summary)
494481

495482
else:
496483
log.error("Unsupported operation: exiting.")

0 commit comments

Comments
 (0)