Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow memap.py to process memory bank information #345

Merged
merged 8 commits into from
Sep 24, 2024

Conversation

multiplemonomials
Copy link
Collaborator

Summary of changes

This PR rewrites memap.py to enable it to process memory bank information and print percentage used of each memory bank in the MCU.

For some background, memap.py is a script called each time an application has been built to display information about how much memory of each type an application uses. It gets this information by parsing the map file generated by the linker when it builds the application. It prints a report like this:

| Module             |           .text |       .data |          .bss |
|--------------------|-----------------|-------------|---------------|
| [fill]             |       197(+197) |     16(+16) |       35(+35) |
| [lib]\ADS124S0x.a  |       984(+984) |       0(+0) |         0(+0) |
| [lib]\c.a          |   79837(+79837) | 1708(+1708) |     373(+373) |
| [lib]\gcc.a        |     1752(+1752) |       0(+0) |         0(+0) |
| [lib]\microdaq.a   |       446(+446) |       0(+0) |         0(+0) |
| [lib]\misc         |       292(+292) |     12(+12) |       25(+25) |
| mbed-os\CMakeFiles |   51908(+51908) |   448(+448) | 11623(+11623) |
| src\CMakeFiles     |     1656(+1656) |     16(+16) |   1800(+1800) |
| Subtotals          | 137072(+137072) | 2200(+2200) | 13856(+13856) |
Total Static RAM memory (data + bss): 16056(+16056) bytes
Total Flash memory (text + data): 139272(+139272) bytes

This PR augments the script to read in the memory bank information and track which memory bank each of the symbols resides in. This enables it to print a breakdown like this:

RAM Bank SRAM_D2: 278528(+0)/294912 bytes used, 94.4% (+0.0%) used
RAM Bank SRAM_D1: 16064(+0)/524288 bytes used, 3.1% (+0.0%) used
RAM Bank SRAM_D3: 0(+0)/65536 bytes used, 0.0% (+0.0%) used
RAM Bank SRAM_DTC: 256(+0)/131072 bytes used, 0.2% (+0.0%) used
RAM Bank SRAM_ITC: 0(+0)/65536 bytes used, 0.0% (+0.0%) used
RAM Bank SRAM_BKUP: 0(+0)/4096 bytes used, 0.0% (+0.0%) used
ROM Bank IROM1: 139280(+0)/2097152 bytes used, 6.6% (+0.0%) used

This should be very useful as, traditionally, Mbed makes it easy to see how much space you are using, but hard to tell how close you are to running out of space. It's especially bad since a lot of devices will say they have some amount of memory, but that memory is actually split into different banks (e.g ITCM, DTCM, AXI SRAM, D2 SRAM, etc), only some of which can actually be used by Mbed. This report should give you much more detailed information about how much memory you have and how much of it is used.

memap.py is a somewhat old python script, and lacks a lot of more modern conveniences like type annotations and dataclasses. I tried to add in type info and other refactorings where possible, without completely taking the script down to the studs and rebuilding. This might be worth doing at some point but I don't realistically think I have time at present.

One thing I did add was correct a lot of incorrect usages of the term "module", and add a new glossary at the top that explains what some of the terms used in the code actually mean.

Impact of changes

  • Building executables now prints a memory bank summary

Migration actions required

None

Documentation

None


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[X] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

tools/python/memap/memap.py Outdated Show resolved Hide resolved
tools/python/memap/memap.py Outdated Show resolved Hide resolved
tools/python/memap/memap.py Outdated Show resolved Hide resolved
tools/python/memap/memap.py Outdated Show resolved Hide resolved
tools/python/memap/memap.py Outdated Show resolved Hide resolved
tools/python/memap/memap.py Show resolved Hide resolved
@multiplemonomials multiplemonomials merged commit 0a76520 into master Sep 24, 2024
10 checks passed
@multiplemonomials multiplemonomials deleted the dev/memap-memory-banks branch September 24, 2024 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants