Skip to content

Commit 26b8477

Browse files
committed
Add glob support for symbols, to quickly figure out sizes
1 parent 5a96f77 commit 26b8477

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

scripts/tools/file_size_from_nm.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
# pandas
4242
# plotly
4343

44+
import fnmatch
4445
import logging
4546
import re
4647
import subprocess
@@ -718,14 +719,18 @@ def symbols_from_nm(elf_file: str) -> list[Symbol]:
718719
return symbols
719720

720721

721-
def fetch_symbols(elf_file: str, fetch: FetchStyle) -> Tuple[list[Symbol], str]:
722+
def fetch_symbols(elf_file: str, fetch: FetchStyle, glob_filter: Optional[str]) -> Tuple[list[Symbol], str]:
722723
"""Returns the sumbol list and the separator used to split symbols
723724
"""
724725
match fetch:
725726
case FetchStyle.NM:
726-
return symbols_from_nm(elf_file), "::"
727+
symbols, separator = symbols_from_nm(elf_file), "::"
727728
case FetchStyle.OBJDUMP:
728-
return symbols_from_objdump(elf_file), '/'
729+
symbols, separator = symbols_from_objdump(elf_file), '/'
730+
if glob_filter is not None:
731+
symbols = [s for s in symbols if fnmatch.fnmatch(s.name, glob_filter)]
732+
733+
return symbols, separator
729734

730735

731736
def list_id(tree_path: list[str]) -> str:
@@ -833,6 +838,11 @@ def compute_symbol_diff(orig: list[Symbol], base: list[Symbol]) -> list[Symbol]:
833838
default=None,
834839
help="Zoom in the graph to ONLY the specified path as root (e.g. ::chip::app)",
835840
)
841+
@click.option(
842+
"--glob-filter",
843+
default=None,
844+
help="Glob filter by name",
845+
)
836846
@click.option(
837847
"--strip",
838848
default=None,
@@ -855,15 +865,16 @@ def main(
855865
zoom: Optional[str],
856866
strip: Optional[str],
857867
diff: Optional[str],
868+
glob_filter: Optional[str],
858869
):
859870
log_fmt = "%(asctime)s %(levelname)-7s %(message)s"
860871
coloredlogs.install(level=__LOG_LEVELS__[log_level], fmt=log_fmt)
861872

862-
symbols, separator = fetch_symbols(elf_file, __FETCH_STYLES__[fetch_via])
873+
symbols, separator = fetch_symbols(elf_file, __FETCH_STYLES__[fetch_via], glob_filter)
863874
title = elf_file
864875

865876
if diff:
866-
diff_symbols, _ = fetch_symbols(diff, __FETCH_STYLES__[fetch_via])
877+
diff_symbols, _ = fetch_symbols(diff, __FETCH_STYLES__[fetch_via], glob_filter)
867878
symbols = compute_symbol_diff(symbols, diff_symbols)
868879
title = f"{elf_file} COMPARED TO {diff}"
869880

0 commit comments

Comments
 (0)