feat: add memory usage analyser tool

Add command line tool that reports per-function code size and stack
usage from ELF binaries built with Rust stack size metadata. Support
table output on stdout by default, and CSV/JSON exports for integration
with other tooling.

Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I0ed2b14f32c6acc853b2dd79368bf85a9446cc5d
7 files changed
tree: ddcea48a2774d7dd3f092ad2e936589c463b4764
  1. src/
  2. .gitignore
  3. Cargo.lock
  4. Cargo.toml
  5. dco.txt
  6. LICENSE
  7. README.md
README.md

Memory Usage Analyser

A tool to generate statistics from an ELF file, such as code and stack usage on a per-function basis. Only software implemented in Rust can be analysed through this tool, as it expects symbols to be encoded per Rust mangling rules. Outputs data in a number of formats, such as simple text, CSV or JSON, for possible integration with other tools.

Usage

  1. Build the project you want to analyse with stack size metadata enabled.

    For a Rust project, this requires the Rust nightly toolchain and the -Zemit-stack-sizes compiler flag. For release builds, also keep debug information in the output file with -C strip=none.

    RUSTFLAGS="-Zemit-stack-sizes -C strip=none" cargo +nightly build --release
    
  2. Build Memory Usage Analyser.

    cargo build
    
  3. Run Memory Usage Analyser on the generated ELF file.

    memory-usage-analyser -i path/to/project/target/output
    

    By default, the tool prints a table containing each function's address, stack usage, code size and name.

  4. Export the results if you want to process them with other tools.

    memory-usage-analyser -i path/to/project/target/output -O json -o memory-usage.json
    memory-usage-analyser -i path/to/project/target/output -O csv -o memory-usage.csv
    

License

The project is provided under the BSD-3-Clause license, see LICENSE. Contributions to this project are accepted under the same license and must also be made under the terms of the Developer Certificate of Origin, confirming that the code submitted can (legally) become part of the project.

Maintainers

memory-usage-analyser is a trustedfirmware.org maintained project. All contributions are ultimately merged by the maintainers listed below.

Contributing

Please follow the directions of the Trusted Firmware Processes

Contributions are handled through review.trustedfirmware.org.


Copyright The memory-usage-analyser Contributors.