Skip to content

Commit be427b5

Browse files
committed
Merge remote-tracking branch 'upstream/main' into config-handling
2 parents 1694935 + 77e6394 commit be427b5

6 files changed

Lines changed: 39 additions & 20 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ In `bench_runner.toml`, the `longitudinal_plot` table has a `subplots` key which
149149
- `base`: The base version to compare to. Should be a fully-specified version, e.g. "3.13.0".
150150
- `version`: The version series to use as a head. Should be a 2-part version, e.g. "3.14"
151151
- `flags`: (optional) A list of flags to match to for the head versions
152+
- `runners`: (optional) A list of nicknames of runners to plot. Defaults to all runners.
152153

153154
For example:
154155

@@ -157,7 +158,8 @@ For example:
157158
subplots = [
158159
{ base = "3.10.4", version = "3.11" },
159160
{ base = "3.12.0", version = "3.13" },
160-
{ base = "3.13.0", version = "3.14" },
161+
{ base = "3.13.0", version = "3.14", runners = ["linux1", "linux2"] },
162+
{ base = "3.13.0", version = "3.14", runners = ["windows1", "macos1"] },
161163
{ base = "3.13.0", version = "3.14", flags = ["JIT"] }
162164
]
163165
```
@@ -172,6 +174,7 @@ In `bench_runner.toml`, the `flag_effect_plot` table has a `subplots` key which
172174
- `version`: The version series to compare. Should be a 2-part version, e.g. "3.14"
173175
- `head_flags`: A list of flags to use as the head.
174176
- `base_flags`: (optional) A list of flags to use as the base. By default, this is a default build, i.e. no flags.
177+
- `runners`: (optional) A list of nicknames of runners to plot. Defaults to all runners.
175178
- `runner_map`: (optional) If you need to map a runner to a base in a
176179
different runner, you can provide that mapping here. For example, with
177180
tail-calling, you may want to compare runners configured to use clang
@@ -192,6 +195,7 @@ head_flags = ["JIT"]
192195
name = "Tail calling interpreter"
193196
version = "3.14"
194197
head_flags = ["TAILCALL"]
198+
runners = ["linux_clang"]
195199
runner_map = { linux_clang = "linux" }
196200
```
197201

bench_runner/plot.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class Subplot:
222222
base: str
223223
version: str
224224
flags: list[str] = dataclasses.field(default_factory=list)
225+
runners: list[str] = dataclasses.field(default_factory=list)
225226

226227
def __post_init__(self):
227228
if not util.valid_version(self.base):
@@ -291,23 +292,29 @@ def get_comparison_value(ref, r, base):
291292
axs = _axs
292293

293294
results = [r for r in results if r.fork == "python"]
295+
runners = cfg.runners.values()
294296

295297
for subcfg, ax in zip(all_cfg, axs):
296298
version = [int(x) for x in subcfg.version.split(".")]
297299
ver_results = [
298300
r for r in results if list(r.parsed_version.release[0:2]) == version
299301
]
302+
if subcfg.runners:
303+
cfg_runners = [r for r in runners if r.nickname in subcfg.runners]
304+
else:
305+
cfg_runners = runners
300306

301-
subtitle = f"Python {subcfg.version}.x vs. {subcfg.base}"
302307
if len(subcfg.flags):
303-
subtitle += f" ({','.join(subcfg.flags)})"
308+
titleflags = f" ({','.join(subcfg.flags)})"
309+
else:
310+
titleflags = ""
311+
subtitle = f"Python {subcfg.version}.x{titleflags} vs. {subcfg.base}"
304312
ax.set_title(subtitle)
305313

306314
first_runner = True
307315

308-
for runner in cfg.runners.values():
309-
assert runner.plot is not None
310-
316+
for runner in cfg_runners:
317+
assert runner.plot is not None # typing
311318
runner_results = [
312319
r
313320
for r in ver_results
@@ -410,6 +417,7 @@ class Subplot:
410417
head_flags: list[str] = dataclasses.field(default_factory=list)
411418
base_flags: list[str] = dataclasses.field(default_factory=list)
412419
runner_map: dict[str, str] = dataclasses.field(default_factory=dict)
420+
runners: list[str] = dataclasses.field(default_factory=list)
413421

414422
def __post_init__(self):
415423
if (
@@ -495,7 +503,8 @@ def get_comparison_value(ref, r, force_valid):
495503
)
496504

497505
for runner in cfg.runners.values():
498-
assert runner.plot is not None
506+
if subplot.runners and runner.nickname not in subplot.runners:
507+
continue
499508
runner_is_mapped = runner.nickname in subplot.runner_map
500509
if subplot.runner_map and not runner_is_mapped:
501510
continue

bench_runner/result.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
CombinedData = list[tuple[str, np.ndarray | None, float]]
3535

3636

37+
@functools.lru_cache(maxsize=100)
38+
def _load_contents(filename: Path) -> dict[str, Any]:
39+
with filename.open("rb") as fd:
40+
return json.load(fd)
41+
42+
3743
def _clean(string: str) -> str:
3844
"""
3945
Clean an arbitrary string to be suitable for a filename.
@@ -599,16 +605,15 @@ def result_info(self) -> tuple[str | None, str | None, str | None]:
599605
f"Unknown result type (extra={self.extra} suffix={self.suffix})"
600606
)
601607

602-
@functools.cached_property
608+
@property
603609
def contents(self) -> dict[str, Any]:
604-
with self.filename.open("rb") as fd:
605-
return json.load(fd)
610+
return _load_contents(self.filename)
606611

607-
@property
612+
@functools.cached_property
608613
def metadata(self) -> dict[str, Any]:
609614
return self.contents.get("metadata", {})
610615

611-
@property
616+
@functools.cached_property
612617
def commit_datetime(self) -> str:
613618
if self._commit_datetime is not None:
614619
return self._commit_datetime
@@ -618,7 +623,7 @@ def commit_datetime(self) -> str:
618623
def commit_date(self) -> str:
619624
return self.commit_datetime[:10]
620625

621-
@property
626+
@functools.cached_property
622627
def run_datetime(self) -> str:
623628
return self.contents["benchmarks"][0]["runs"][0]["metadata"]["date"]
624629

bench_runner/templates/workflow_bootstrap.src.py

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

6060
def main():
6161
venv = Path("venv")
62-
print("::group::Creating venv")
62+
print("::group::Creating venv", file=sys.stderr)
6363
create_venv(venv)
64-
print("::endgroup::")
65-
print("::group::Installing requirements")
64+
print("::endgroup::", file=sys.stderr)
65+
print("::group::Installing requirements", file=sys.stderr)
6666
install_requirements(venv)
67-
print("::endgroup::")
67+
print("::endgroup::", file=sys.stderr)
6868

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

bench_runner/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ def valid_version(version: str) -> bool:
109109

110110
@contextlib.contextmanager
111111
def log_group(text: str) -> Iterator:
112-
print(f"::group::{text}")
112+
print(f"::group::{text}", file=sys.stderr)
113113
try:
114114
yield
115115
finally:
116-
print("::endgroup::")
116+
print("::endgroup::", file=sys.stderr)
117117

118118
def track(iterable: Iterable, name: str) -> Iterable:
119119
with log_group(name):

tests/data/bench_runner.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ plot = { name = "Linux", color = "C0" }
1212
subplots = [
1313
{ base = "3.10.4", version = "3.11" },
1414
{ base = "3.12.0", version = "3.13" },
15-
{ base = "3.13.0b2", version = "3.14" },
15+
{ base = "3.13.0b2", version = "3.14", runners = ["linux"] },
1616
{ base = "3.13.0b2", version = "3.14", flags = ["JIT"] }
1717
]
1818

1919
[flag_effect_plot]
2020
subplots = [
2121
{ name = "JIT", version = "3.14", head_flags = ["JIT"] },
22+
{ name = "NOGIL", version = "3.14", head_flags = ["NOGIL"], runners = ["linux"] },
2223
]
2324

2425
[benchmark_longitudinal_plot]

0 commit comments

Comments
 (0)