Skip to content

Commit 7729802

Browse files
committed
scripts: footprint: extend the size_report with filters
Add two new parameters to the script: - -l, --lowestLimit: set what percentage is the lowest limit for printing a symbol. - -m, --maxItems: how many items in total should the script print. Reasoning for the first would be that without it, the script prints hundreds of lines of symbols and it's hard to keep track of what feature(s) are the most impactful on ROM/ RAM. So by setting the lowestLimit to 1, the output gets trimmed down to the essential symbols that have an impact. Reasoning for the second would be that it gives the user the chance to select how many symbols to be printed (can be used together with lowestLimit or standalone). When they're not set, both parameters are given the default value (0), which makes the script behave as it normally would without them. -> the user may use them if he wants or not use them/ ignore them/ be completely unaware of them and everything works as before. Recommended usage: Add to Kconfig: config REPORT_LOWEST_LIMIT int "Minimum percentage to show in the report (0-100)" default 0 range 0 100 help Only show symbols that use at least this percentage of total ROM. Set to 0 to show all symbols. Leaving it on default (0), includes everything. config REPORT_MAX_ITEMS int "Maximum number of symbols to show in the report" default 0 help Only shows as many symbols as defined by this option. Leaving it on default (0), includes everything. Add to prj.conf or board.conf: CONFIG_REPORT_LOWEST_LIMIT=1 CONFIG_REPORT_MAX_ITEMS=10 Signed-off-by: TudorBalus <[email protected]>
1 parent 28bdaa3 commit 7729802

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

cmake/reports/CMakeLists.txt

100644100755
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ set(flag_for_rom_report rom)
55
set(flag_for_footprint all)
66
set(report_depth 99)
77

8+
if(CONFIG_REPORT_LOWEST_LIMIT)
9+
set(REPORT_LOWEST_LIMIT ${CONFIG_REPORT_LOWEST_LIMIT})
10+
else()
11+
set(REPORT_LOWEST_LIMIT 0)
12+
endif()
13+
if(CONFIG_REPORT_MAX_ITEMS)
14+
set(REPORT_MAX_ITEMS ${CONFIG_REPORT_MAX_ITEMS})
15+
else()
16+
set(REPORT_MAX_ITEMS 0)
17+
endif()
818
if(DEFINED ZEPHYR_WORKSPACE)
919
set(workspace_arg "--workspace=${ZEPHYR_WORKSPACE}")
1020
elseif(DEFINED WEST_TOPDIR)
@@ -21,6 +31,8 @@ foreach(report ram_report rom_report)
2131
-o ${CMAKE_BINARY_DIR}
2232
${workspace_arg}
2333
-d ${report_depth}
34+
-l ${REPORT_LOWEST_LIMIT}
35+
-m ${REPORT_MAX_ITEMS}
2436
${flag_for_${report}}
2537
DEPENDS ${logical_target_for_zephyr_elf}
2638
$<TARGET_PROPERTY:zephyr_property_target,${report}_DEPENDENCIES>

scripts/footprint/size_report

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,12 @@ def print_any_tree(root, total_size, depth):
752752
"""
753753
Print the symbol tree.
754754
"""
755+
global args
756+
maxItems = None
757+
758+
if args.maxItems and args.maxItems != 0:
759+
maxItems = args.maxItems
760+
755761
print('{:98s} {:>7s} {:>7s} {:11s} {:16s}'.format(
756762
Fore.YELLOW + "Path", "Size", "%", " Address", "Section" + Fore.RESET))
757763
print('=' * 138)
@@ -760,6 +766,19 @@ def print_any_tree(root, total_size, depth):
760766
s = str(row.node._size).rjust(100-f)
761767
percent = 100 * float(row.node._size) / float(total_size)
762768

769+
if args.lowestLimit and args.lowestLimit != 0:
770+
# If the current symbol's footprint percentage is below the threshold -> skip it
771+
if percent < args.lowestLimit:
772+
continue
773+
774+
# Only print as many items as the user configured
775+
if args.maxItems and args.maxItems != 0:
776+
maxItems -= 1
777+
778+
if maxItems < 0:
779+
break
780+
781+
763782
hex_addr = "-"
764783
section_name = ""
765784
cc = cr = ""
@@ -805,6 +824,10 @@ def parse_args():
805824
parser.add_argument("-v", "--verbose", action="store_true",
806825
help="Print extra debugging information")
807826
parser.add_argument("--json", help="store results in a JSON file.")
827+
parser.add_argument("-l", "--lowestLimit", dest="lowestLimit",
828+
type=int, default=0, help="set what percentage is the lowest limit for printing a symbol.")
829+
parser.add_argument("-m", "--maxItems", dest="maxItems",
830+
type=int, default=0, help="how many items in total should the script print.")
808831
args = parser.parse_args()
809832

810833

0 commit comments

Comments
 (0)