# Tracking Firmware Code Size | Interrupt

**URL:** <https://community.memfault.com/t/tracking-firmware-code-size-interrupt/161>\
**Category:** Blog\
**Created:** [March 18, 2020, 4:04am UTC](https://community.memfault.com/t/tracking-firmware-code-size-interrupt/161 "2020-03-18T04:04:54Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![chrisc](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.memfault.com/chrisc/32/22_2.png) [@chrisc](https://community.memfault.com/u/chrisc)\
**Post date:** [March 28, 2020, 6:02pm UTC](https://community.memfault.com/t/tracking-firmware-code-size-interrupt/161/5 "2020-03-28T18:02:18Z")

</div>

> What strategy would you follow?
> 
> Our long-term goal would be to have a map of occupation of the memory regions that informs us how much the different compile units fill.

Under the hood, `arm-none-eabi-size` is just walking through the ELF sections (output you would see from `arm-none-eabi-readelf -S <your_file.elf>` and inspecting the sh\_flags in the [section header](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#Section_header). The rules it uses are:

- If the section is not allocated (SHF\_ALLOC == 0), don’t count it
- if the section is executable (SHF\_EXECINSTR == 1) or the section is not writable (SHF\_WRITE == 0), add to `text` count
- If the section has no data (SHT\_NOBITS == 1), add it to the `bss` count else add it to the `data` count

You could use [pyelftools](https://github.com/eliben/pyelftools) to load the elf and compute text/data/bss sums for each memory region you want using those rules.

---

_[View the full topic](https://community.memfault.com/t/tracking-firmware-code-size-interrupt/161)._
