blob: 99149b5470b0888b6c57e19d025ba58fc67049ae [file] [log] [blame]
Harrison Mutaie9bc4882023-02-23 10:33:58 +00001#!/usr/bin/env python3
2
3#
4# Copyright (c) 2023, Arm Limited. All rights reserved.
5#
6# SPDX-License-Identifier: BSD-3-Clause
7#
8
9from pathlib import Path
10
11import click
12from memory.buildparser import TfaBuildParser
13from memory.printer import TfaPrettyPrinter
14
15
16@click.command()
17@click.option(
18 "-r",
19 "--root",
20 type=Path,
21 default=None,
22 help="Root containing build output.",
23)
24@click.option(
25 "-p",
26 "--platform",
27 show_default=True,
28 default="fvp",
29 help="The platform targeted for analysis.",
30)
31@click.option(
32 "-b",
33 "--build-type",
34 default="release",
35 help="The target build type.",
36 type=click.Choice(["debug", "release"], case_sensitive=False),
37)
38@click.option(
Harrison Mutai372b8802023-02-23 11:30:17 +000039 "-f",
40 "--footprint",
41 is_flag=True,
42 show_default=True,
43 help="Generate a high level view of memory usage by memory types.",
44)
45@click.option(
Harrison Mutai0c0afde2023-02-23 11:30:55 +000046 "-t",
47 "--tree",
48 is_flag=True,
49 help="Generate a hierarchical view of the modules, segments and sections.",
50)
51@click.option(
52 "--depth",
53 default=3,
54 help="Generate a virtual address map of important TF symbols.",
55)
56@click.option(
Harrison Mutaie9bc4882023-02-23 10:33:58 +000057 "-s",
58 "--symbols",
59 is_flag=True,
Harrison Mutaie9bc4882023-02-23 10:33:58 +000060 help="Generate a map of important TF symbols.",
61)
62@click.option("-w", "--width", type=int, envvar="COLUMNS")
63@click.option(
64 "-d",
65 is_flag=True,
66 default=False,
67 help="Display numbers in decimal base.",
68)
Harrison Mutai79d079b2023-06-07 11:28:16 +010069@click.option(
70 "--no-elf-images",
71 is_flag=True,
72 help="Analyse the build's map files instead of ELF images.",
73)
Harrison Mutaie9bc4882023-02-23 10:33:58 +000074def main(
75 root: Path,
76 platform: str,
77 build_type: str,
Harrison Mutai0c0afde2023-02-23 11:30:55 +000078 footprint: str,
79 tree: bool,
Harrison Mutaie9bc4882023-02-23 10:33:58 +000080 symbols: bool,
Harrison Mutai0c0afde2023-02-23 11:30:55 +000081 depth: int,
Harrison Mutaie9bc4882023-02-23 10:33:58 +000082 width: int,
83 d: bool,
Harrison Mutai79d079b2023-06-07 11:28:16 +010084 no_elf_images: bool,
Harrison Mutaie9bc4882023-02-23 10:33:58 +000085):
86 build_path = root if root else Path("build/", platform, build_type)
87 click.echo(f"build-path: {build_path.resolve()}")
88
Harrison Mutai79d079b2023-06-07 11:28:16 +010089 parser = TfaBuildParser(build_path, map_backend=no_elf_images)
Harrison Mutaie9bc4882023-02-23 10:33:58 +000090 printer = TfaPrettyPrinter(columns=width, as_decimal=d)
91
Harrison Mutai0c0afde2023-02-23 11:30:55 +000092 if footprint or not (tree or symbols):
Harrison Mutai372b8802023-02-23 11:30:17 +000093 printer.print_footprint(parser.get_mem_usage_dict())
94
Harrison Mutai0c0afde2023-02-23 11:30:55 +000095 if tree:
96 printer.print_mem_tree(
97 parser.get_mem_tree_as_dict(), parser.module_names, depth=depth
98 )
99
Harrison Mutaie9bc4882023-02-23 10:33:58 +0000100 if symbols:
101 expr = (
102 r"(.*)(TEXT|BSS|RODATA|STACKS|_OPS|PMF|XLAT|GOT|FCONF"
Michal Simek80c530e2023-04-27 14:26:03 +0200103 r"|R.M)(.*)(START|UNALIGNED|END)__$"
Harrison Mutaie9bc4882023-02-23 10:33:58 +0000104 )
105 printer.print_symbol_table(
106 parser.filter_symbols(parser.symbols, expr), parser.module_names
107 )
108
109
110if __name__ == "__main__":
111 main()