Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

Commit 8de73b7

Browse files
committed
build: meson benchmarks autogen
1 parent bdcf49f commit 8de73b7

3 files changed

Lines changed: 71 additions & 6 deletions

File tree

benchmarks/meson.build

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@ benchmarks_exe = executable(
1010
build_by_default: false,
1111
)
1212

13-
# manually written, list all benchmarks with:
14-
# builddir/benchmarks/msft_proxy_benchmarks --benchmark_list_tests
13+
autogen_benchmarks = custom_target(
14+
command: [
15+
autogen_benchmarks_exe,
16+
custom_target(
17+
command: [benchmarks_exe, '--benchmark_list_tests'],
18+
capture: true,
19+
output: 'tests.txt',
20+
),
21+
meson.current_source_dir() / 'meson.build',
22+
],
23+
output: 'autogen.stamp',
24+
build_by_default: true,
25+
)
26+
27+
#pragma autogen push
1528
benchmarks = {
1629
'ObjectCreation': [
17-
'BM_SmallObjectCreationWithProxy',
1830
'BM_SmallObjectCreationWithProxy_Shared',
1931
'BM_SmallObjectCreationWithProxy_SharedPooled',
2032
'BM_SmallObjectCreationWithUniquePtr',
@@ -31,7 +43,6 @@ benchmarks = {
3143
'BM_LargeObjectCreationWithAny',
3244
],
3345
'ObjectInvocation': [
34-
'BM_SmallObjectInvocationViaProxy',
3546
'BM_SmallObjectInvocationViaProxy_Shared',
3647
'BM_SmallObjectInvocationViaProxyView',
3748
'BM_SmallObjectInvocationViaVirtualFunction',
@@ -44,8 +55,7 @@ benchmarks = {
4455
'BM_LargeObjectInvocationViaVirtualFunction_Shared',
4556
'BM_LargeObjectInvocationViaVirtualFunction_RawPtr',
4657
],
47-
'ObjectOperation': [
48-
'BM_SmallObjectRelocationViaProxy',
58+
'ObjectRelocation': [
4959
'BM_SmallObjectRelocationViaProxy_NothrowRelocatable',
5060
'BM_SmallObjectRelocationViaUniquePtr',
5161
'BM_SmallObjectRelocationViaAny',
@@ -55,6 +65,7 @@ benchmarks = {
5565
'BM_LargeObjectRelocationViaAny',
5666
],
5767
}
68+
#pragma autogen pop
5869

5970
foreach suite : benchmarks.keys()
6071
foreach name : benchmarks[suite]
@@ -63,6 +74,7 @@ foreach suite : benchmarks.keys()
6374
benchmarks_exe,
6475
args: [f'--benchmark_filter=^@name@$'],
6576
suite: suite,
77+
depends: autogen_benchmarks,
6678
)
6779
endforeach
6880
endforeach

tools/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
autogen_tests_exe = find_program('./meson_autogen_tests.py')
22
autogen_doctest_exe = find_program('./meson_autogen_doctest.py')
3+
autogen_benchmarks_exe = find_program('./meson_autogen_benchmarks.py')

tools/meson_autogen_benchmarks.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
# pyright: strict
3+
4+
import re
5+
import sys
6+
from pathlib import Path
7+
8+
from mesonbuild import mformat
9+
10+
PATTERN = re.compile(r"(?=[A-Z])")
11+
12+
benchmarkfile = Path(sys.argv[1])
13+
mesonfile = Path(sys.argv[2])
14+
15+
with benchmarkfile.open(encoding="utf-8") as f:
16+
bench = [line.rstrip() for line in f.readlines()]
17+
18+
with mesonfile.open(encoding="utf-8") as f:
19+
build = f.readlines()
20+
21+
begin = -1
22+
end = -1
23+
24+
for i, line in enumerate(build):
25+
if begin == -1 and line.strip() == "#pragma autogen push":
26+
begin = i + 1
27+
elif end == -1 and line.strip() == "#pragma autogen pop":
28+
end = i
29+
30+
if begin == -1 or end == -1:
31+
raise ValueError
32+
33+
benchmarks: "dict[str, list[str]]" = {}
34+
35+
for name in bench:
36+
suite = "".join(PATTERN.split(name.split('_', 1)[1])[2:4])
37+
if suite not in benchmarks:
38+
benchmarks[suite] = []
39+
else:
40+
benchmarks[suite].append(name)
41+
42+
config = mformat.get_meson_format([mesonfile])
43+
formatter = mformat.Formatter(config, False, False)
44+
pretty = formatter.format(f"{benchmarks = }", mesonfile)
45+
46+
if pretty == "".join(build[begin:end]):
47+
exit()
48+
49+
with mesonfile.open("w", encoding="utf-8") as f:
50+
f.writelines(build[:begin])
51+
_ = f.write(pretty)
52+
f.writelines(build[end:])

0 commit comments

Comments
 (0)