Skip to content

Commit cec9758

Browse files
authored
chore: measure dynamic symbols in benchmarks (#11568)
Add back the dynamic symbol measurements that were removed in #11264.
1 parent c447793 commit cec9758

File tree

1 file changed

+25
-7
lines changed
  • tests/bench-radar/size

1 file changed

+25
-7
lines changed

tests/bench-radar/size/run

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import json
4+
import subprocess
45
from pathlib import Path
56
from typing import Iterable
67

@@ -17,14 +18,13 @@ def print_result(metric: str, value: float, unit: str | None = None) -> None:
1718
print(f"radar::measurement={json.dumps(data)}")
1819

1920

20-
def measure_bytes(topic: str, paths: Iterable[Path], files: bool = True) -> None:
21+
def measure_bytes(topic: str, paths: Iterable[Path]) -> None:
2122
amount = 0
2223
total = 0
2324
for path in paths:
2425
amount += 1
2526
total += path.stat().st_size
26-
if files:
27-
print_result(f"{topic}//files", amount)
27+
print_result(f"{topic}//files", amount)
2828
print_result(f"{topic}//bytes", total, "B")
2929

3030

@@ -39,11 +39,29 @@ def measure_lines(topic: str, paths: Iterable[Path]) -> None:
3939
print_result(f"{topic}//lines", total)
4040

4141

42+
def measure_bytes_for_file(topic: str, path: Path) -> int:
43+
size = path.stat().st_size
44+
print_result(f"{topic}//bytes", size, "B")
45+
return size
46+
47+
48+
def measure_symbols_for_file(topic: str, path: Path) -> int:
49+
result = subprocess.run(
50+
["nm", "--extern-only", "--defined-only", path],
51+
capture_output=True,
52+
encoding="utf-8",
53+
check=True,
54+
)
55+
count = len(result.stdout.splitlines())
56+
print_result(f"{topic}//dynamic symbols", count)
57+
return count
58+
59+
4260
if __name__ == "__main__":
43-
measure_bytes(
44-
"size/libleanshared.so",
45-
[STAGE3_LEAN / "libleanshared.so"],
46-
files=False,
61+
measure_bytes_for_file("size/libleanshared.so", STAGE3_LEAN / "libleanshared.so")
62+
measure_symbols_for_file("size/libleanshared.so", STAGE3_LEAN / "libleanshared.so")
63+
measure_symbols_for_file(
64+
"size/libLake_shared.so", STAGE3_LEAN / "libLake_shared.so"
4765
)
4866

4967
# Stdlib

0 commit comments

Comments
 (0)