scripts: size_report: Fix tree build for symbol copies

Fix the memory footprint tree build for symbols with copies,
e.g. static inline functions which are local per each compilation
unit. Copies have the same path and symbol name, but different
memory blocks associated, so they have to have separate nodes.
Before the fix, these copies were merged into one node, with
summary size and memory address of one of the symbols.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
This commit is contained in:
Dmitrii Golovanov 2024-05-04 16:22:55 +02:00 committed by Anas Nashif
parent b438a74bd0
commit 2005deddb4

View file

@ -641,16 +641,27 @@ def generate_any_tree(symbol_dict, total_size, path_prefix):
results = findall_by_attr(root, cur, name="_identifier") results = findall_by_attr(root, cur, name="_identifier")
if results: if results:
item = results[0] item = results[0]
item._size += size if not hasattr(item, 'address'):
# Passing down through a non-terminal parent node.
parent = item parent = item
parent._size += size
else: else:
# Another symbol node here with the same name; stick to its parent as well.
parent = item.parent
node = TreeNode(name=str(part), identifier=cur, size=size, parent=parent)
else:
# There is no such terminal symbol in the tree yet; let's add it.
if node: if node:
parent = node parent = node
node = TreeNode(name=str(part), identifier=cur, size=size, parent=parent) node = TreeNode(name=str(part), identifier=cur, size=size, parent=parent)
# Set memory block address and section only on terminal symbol nodes. if node:
# Don't do it on file and directory level nodes. # Set memory block address and section name properties only for terminal symbol nodes.
# Don't do it on file- and directory- level parent nodes.
node.address = addr node.address = addr
node.section = section node.section = section
else:
# normally this shouldn't happen; just to detect data or logic errors.
print(f"ERROR: no end node created for {root}, {path}, 0x{addr:08x}+{size}@{section}")
# #
# Mapping paths to tree nodes # Mapping paths to tree nodes