From d475f9865b5c9155b2be2b9dc5eda8b46b6c00cf Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Tue, 25 May 2021 11:16:34 -0700 Subject: [PATCH] scripts: size_report: add tree node for WORKSPACE Add a tree node to group files under WORKSPACE so that they won't be shown with full path. The WORKSPACE is usually the same as WEST_TOPDIR unless ZEPHYR_WORKSPACE is defined during build. Signed-off-by: Daniel Leung --- cmake/reports/CMakeLists.txt | 7 ++++++ scripts/footprint/size_report | 42 +++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/cmake/reports/CMakeLists.txt b/cmake/reports/CMakeLists.txt index 651e1050e92..4749e8f7446 100644 --- a/cmake/reports/CMakeLists.txt +++ b/cmake/reports/CMakeLists.txt @@ -4,6 +4,12 @@ set(flag_for_ram_report ram) set(flag_for_rom_report rom) set(report_depth 99) +if(DEFINED ZEPHYR_WORKSPACE) + set(workspace_arg "--workspace=${ZEPHYR_WORKSPACE}") +elseif(DEFINED WEST_TOPDIR) + set(workspace_arg "--workspace=${WEST_TOPDIR}") +endif() + foreach(report ram_report rom_report) add_custom_target( ${report} @@ -12,6 +18,7 @@ foreach(report ram_report rom_report) -k ${ZEPHYR_BINARY_DIR}/${KERNEL_ELF_NAME} -z ${ZEPHYR_BASE} -o ${CMAKE_BINARY_DIR} + ${workspace_arg} --json ${CMAKE_BINARY_DIR}/${flag_for_${report}}.json -d ${report_depth} ${flag_for_${report}} diff --git a/scripts/footprint/size_report b/scripts/footprint/size_report index 89e90c85a21..b02812d95de 100755 --- a/scripts/footprint/size_report +++ b/scripts/footprint/size_report @@ -565,12 +565,18 @@ def generate_any_tree(symbol_dict, total_size, path_prefix): # no need for another level. node_zephyr_base = root node_output_dir = root + node_workspace = root node_others = root else: node_zephyr_base = TreeNode('ZEPHYR_BASE', args.zephyrbase) node_output_dir = TreeNode('OUTPUT_DIR', args.output) node_others = TreeNode("/", "/") + if args.workspace: + node_workspace = TreeNode('WORKSPACE', args.workspace) + else: + node_workspace = node_others + # A set of helper function for building a simple tree with a path-like # hierarchy. def _insert_one_elem(root, path, size): @@ -593,8 +599,16 @@ def generate_any_tree(symbol_dict, total_size, path_prefix): parent = node node = TreeNode(name=str(part), identifier=cur, size=size, parent=parent) - zbase = Path(args.zephyrbase) - outd = Path(args.output) + # Mapping paths to tree nodes + path_node_map = [ + [Path(args.zephyrbase), node_zephyr_base], + [Path(args.output), node_output_dir], + ] + + if args.workspace: + path_node_map.append( + [Path(args.workspace), node_workspace] + ) for name, sym in symbol_dict.items(): for symbol in sym: @@ -602,13 +616,16 @@ def generate_any_tree(symbol_dict, total_size, path_prefix): for file in symbol['mapped_files']: path = Path(file, name) if path.is_absolute(): - if zbase in path.parents: - path = path.relative_to(zbase) - dest_node = node_zephyr_base - elif outd in path.parents: - path = path.relative_to(outd) - dest_node = node_output_dir - else: + has_node = False + + for one_path in path_node_map: + if one_path[0] in path.parents: + path = path.relative_to(one_path[0]) + dest_node = one_path[1] + has_node = True + break + + if not has_node: dest_node = node_others else: dest_node = node_no_paths @@ -632,6 +649,11 @@ def generate_any_tree(symbol_dict, total_size, path_prefix): # Only include "others" node if there is something. children.append(node_others) + if args.workspace: + node_workspace.size = sum_node_children_size(node_workspace) + if node_workspace.height != 0: + children.append(node_workspace) + root.children = children # Root node doesn't have sum of symbol size. So sum them up. @@ -691,6 +713,8 @@ def parse_args(): help="Zephyr base path") parser.add_argument("-o", "--output", required=True, help="Output path") + parser.add_argument("-w", "--workspace", default=None, + help="Workspace path (Usually the same as WEST_TOPDIR)") parser.add_argument("target", choices=['rom', 'ram']) parser.add_argument("-d", "--depth", dest="depth", type=int, default=None,