11#!/usr/bin/env python3
22
33import json
4+ import subprocess
45from pathlib import Path
56from 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+
4260if __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