Skip to content

Commit 5b05552

Browse files
authored
Merge pull request #404 from faster-cpython/groups
Show groupings in GHA
2 parents 8c847d5 + db85f4d commit 5b05552

File tree

6 files changed

+92
-44
lines changed

6 files changed

+92
-44
lines changed

bench_runner/result.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import numpy as np
1919
from packaging import version
2020
import pyperf
21-
import rich.progress
2221

2322

2423
from . import bases as mbases
@@ -799,20 +798,20 @@ def find_match(result, candidates, base, func):
799798
bases = []
800799

801800
if progress:
802-
track = rich.progress.track # type: ignore
801+
track = util.track # type: ignore
803802
else:
804803

805804
def track(it, *_args, **_kwargs):
806805
return it
807806

808807
groups = defaultdict(lambda: defaultdict(list))
809-
for result in track(results, description="Loading results"):
808+
for result in track(results, "Loading results"):
810809
if result.fork == "python":
811810
groups[(result.nickname, tuple(result.extra))][
812811
result.benchmark_hash
813812
].append(result)
814813

815-
for result in track(results, description="Matching results to bases"):
814+
for result in track(results, "Matching results to bases"):
816815
candidates = groups[(result.nickname, tuple(result.extra))]
817816

818817
if (

bench_runner/scripts/generate_results.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
import rich
15-
import rich.progress
1615
import rich_argparse
1716

1817

@@ -70,9 +69,9 @@ def save_generated_results(results: Iterable[Result], force: bool = False) -> No
7069

7170
rich.print(f"Generating {len(work)} derived results")
7271

73-
for func, filename in rich.progress.track(
72+
for func, filename in util.track(
7473
work,
75-
description="Generating results",
74+
"Generating results",
7675
):
7776
func(filename)
7877

@@ -352,9 +351,7 @@ def generate_directory_indices(results: Iterable[Result]) -> None:
352351
entries = get_directory_indices_entries(results)
353352
structure = _tuple_to_nested_dicts(entries)
354353

355-
for dirpath, dirresults in rich.progress.track(
356-
structure.items(), description="Generating indices"
357-
):
354+
for dirpath, dirresults in util.track(structure.items(), "Generating indices"):
358355
with (dirpath / "README.md").open("w") as fd:
359356
fd.write("# Results\n\n")
360357
table.write_md_list(fd, dirresults[None][None])
@@ -392,7 +389,7 @@ def _main(repo_dir: PathLike, force: bool = False, bases: Sequence[str] | None =
392389

393390
memory_benchmarking_results = filter_broken_memory_results(benchmarking_results)
394391

395-
for plot_func, args, kwargs in rich.progress.track(
392+
for plot_func, args, kwargs in util.track(
396393
[
397394
(
398395
plot.longitudinal_plot,
@@ -423,7 +420,7 @@ def _main(repo_dir: PathLike, force: bool = False, bases: Sequence[str] | None =
423420
),
424421
),
425422
],
426-
description="Generating plots",
423+
"Generating plots",
427424
):
428425
plot_func(*args, **kwargs) # type: ignore
429426

bench_runner/scripts/remove_benchmark.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99

1010
import rich
11-
import rich.progress
1211
import rich_argparse
1312

1413

1514
from bench_runner import result
1615
from bench_runner.scripts import generate_results
16+
from bench_runner import util
1717
from bench_runner.util import PathLike
1818

1919

@@ -52,9 +52,7 @@ def _main(benchmarks: Sequence[str], keep_hash: Sequence[str], dry_run: bool = F
5252
if Path("longitudinal.json").is_file():
5353
Path("longitudinal.json").unlink()
5454

55-
for filename in rich.progress.track(
56-
list(Path("results").glob("**/*")), description="Deleting results"
57-
):
55+
for filename in util.track(list(Path("results").glob("**/*")), "Deleting results"):
5856
if filename.is_dir():
5957
continue
6058
if filename.name != "README.md":

bench_runner/scripts/workflow.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from bench_runner import git
2121
from bench_runner.result import has_result
2222
from bench_runner import util
23-
from bench_runner.util import PathLike
23+
from bench_runner.util import log_group, PathLike
2424

2525

2626
from bench_runner.scripts import run_benchmarks as mrun_benchmarks
@@ -266,26 +266,33 @@ def _main(
266266
if pystats and platform != "linux":
267267
raise RuntimeError("Pystats is only supported on Linux")
268268

269-
checkout_cpython(fork, ref, cpython)
269+
with log_group("Checking out CPython"):
270+
checkout_cpython(fork, ref, cpython)
270271

271-
if not should_run(force, fork, ref, machine, False, flags, cpython=cpython):
272-
print("No need to run benchmarks. Skipping...")
273-
return
272+
with log_group("Determining if we need to run benchmarks"):
273+
if not should_run(force, fork, ref, machine, False, flags, cpython=cpython):
274+
print("No need to run benchmarks. Skipping...")
275+
return
274276

275-
checkout_benchmarks()
277+
with log_group("Checking out benchmarks"):
278+
checkout_benchmarks()
276279

277-
match platform:
278-
case "linux" | "macos":
279-
compile_unix(cpython, flags, pgo, pystats)
280-
case "windows":
281-
compile_windows(cpython, flags, pgo, force_32bit)
280+
with log_group("Compiling CPython"):
281+
match platform:
282+
case "linux" | "macos":
283+
compile_unix(cpython, flags, pgo, pystats)
284+
case "windows":
285+
compile_windows(cpython, flags, pgo, force_32bit)
282286

283-
# Print out the version of Python we built just so we can confirm it's the
284-
# right thing in the logs
285-
subprocess.check_call([get_exe_path(cpython, flags, force_32bit), "-VV"])
287+
# Print out the version of Python we built just so we can confirm it's the
288+
# right thing in the logs
289+
subprocess.check_call([get_exe_path(cpython, flags, force_32bit), "-VV"])
286290

287-
install_pyperformance(venv)
288-
tune_system(venv, perf)
291+
with log_group("Installing pyperformance"):
292+
install_pyperformance(venv)
293+
294+
with log_group("Tuning system"):
295+
tune_system(venv, perf)
289296

290297
try:
291298
if Path(".debug").exists():
@@ -303,17 +310,18 @@ def _main(
303310
else:
304311
mode = "benchmark"
305312

306-
mrun_benchmarks._main(
307-
mode,
308-
get_exe_path(cpython, flags, force_32bit),
309-
fork,
310-
ref,
311-
benchmarks,
312-
flags=flags,
313-
run_id=run_id,
314-
test_mode=False,
315-
individual=pystats,
316-
)
313+
with log_group("Running benchmarks"):
314+
mrun_benchmarks._main(
315+
mode,
316+
get_exe_path(cpython, flags, force_32bit),
317+
fork,
318+
ref,
319+
benchmarks,
320+
flags=flags,
321+
run_id=run_id,
322+
test_mode=False,
323+
individual=pystats,
324+
)
317325
finally:
318326
reset_system(venv)
319327

bench_runner/templates/workflow_bootstrap.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ def install_requirements(venv: Path) -> None:
5555

5656
def main():
5757
venv = Path("venv")
58+
print("::group::Creating venv")
5859
create_venv(venv)
60+
print("::endgroup::")
61+
print("::group::Installing requirements")
5962
install_requirements(venv)
63+
print("::endgroup::")
6064

6165
# Now that we've installed the full bench_runner library,
6266
# continue on in a new process...

bench_runner/util.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import contextlib
12
import functools
23
import itertools
34
import os
45
from pathlib import Path
56
import shutil
67
import subprocess
78
import sys
8-
from typing import Literal, TypeAlias, Union
9+
from typing import Iterable, Iterator, Literal, TypeAlias, Union
910

1011

1112
from . import config
@@ -85,3 +86,44 @@ def get_simple_platform() -> Literal["linux", "macos", "windows"]:
8586
elif sys.platform.startswith("win"):
8687
return "windows"
8788
raise RuntimeError(f"Unsupported platform {sys.platform}.")
89+
90+
91+
if os.getenv("GITHUB_ACTIONS") == "true":
92+
93+
@contextlib.contextmanager
94+
def log_group(text: str) -> Iterator:
95+
print(f"::group::{text}")
96+
try:
97+
yield
98+
finally:
99+
print("::endgroup::")
100+
101+
def track(iterable: Iterable, name: str) -> Iterable:
102+
with log_group(name):
103+
yield from iterable
104+
105+
else:
106+
try:
107+
import rich
108+
except ImportError:
109+
110+
@contextlib.contextmanager
111+
def log_group(text: str) -> Iterator:
112+
print(text)
113+
yield
114+
115+
def track(iterable: Iterable, name: str) -> Iterable:
116+
print(name)
117+
return iterable
118+
119+
else:
120+
121+
@contextlib.contextmanager
122+
def log_group(text: str) -> Iterator:
123+
rich.print(f"[b]{text}:[/b]")
124+
yield
125+
126+
def track(iterable: Iterable, name: str) -> Iterable:
127+
from rich.progress import track
128+
129+
return track(iterable, description=name)

0 commit comments

Comments
 (0)