New tool for analyzing static memory size
Posted: Wed Jun 28, 2017 7:05 am
The IDF master branch (as of commit 90f1d42a) has added a new tool (idf_size.py) for analyzing static memory size in your projects. This feature will be in the ESP-IDF v3.0 release, but not the forthcoming v2.1 release.
If you run "make size", the output now looks like this:
There are two new targets, "make size-components" and "make size-files" which break this down further:
This can help you see what code is being linked into the final project binary, and how much memory of various kinds this code uses.
Some Notes
- Output shown above is different from running xtensa-esp32-elf-size libcomponent.a or xtensa-esp32-elf-size file.o. xtensa-esp32-elf-size gives you the size of the entire contents of the unlinked library archive or object file. Whereas the output shown above counts only the parts that were actually linked into the final executable (usually much smaller).
- The available IRAM/DRAM estimates and the available dynamic heap memory at runtime will be a little different. There is some accounting overhead from the heap data structures themselves. Plus the WiFi library, TCP/IP library, etc. all make use of dynamic heap memory.
- The size of each section in the .ELF file will be larger than the sum of all the sizes shown above, because of padding.
- Any external PSRAM is not accounted for. (PSRAM can't be used as static memory, only as dynamic heap memory.)
- There are some more features coming in v3.0 to make it easier to analyze dynamic heap memory usage, as well.
- If you find any bugs, please let us know.
If you run "make size", the output now looks like this:
Code: Select all
Total sizes:
DRAM .data size: 8084 bytes
DRAM .bss size: 1992 bytes
Used static DRAM: 10076 bytes ( 317604 available, 3.1% used)
Used static IRAM: 31732 bytes ( 99340 available, 24.2% used)
Flash code: 52123 bytes
Flash rodata: 12244 bytes
Total image size:~ 104183 bytes (.bin may be padded larger)
Code: Select all
$ make size-components
...
Per-archive contributions to ELF file:
Archive File DRAM .data & .bss IRAM Flash code & rodata Total
libc.a 0 0 0 41430 3055 44485
libcxx.a 4 0 0 5 0 9
libdriver.a 20 0 0 181 1992 2193
libesp32.a 3709 189 6945 3896 3309 18048
libfreertos.a 4144 900 12783 0 1088 18915
libgcc.a 0 0 0 3570 0 3570
libhal.a 0 0 515 0 32 547
liblog.a 8 268 418 82 0 776
libm.a 0 0 0 88 0 88
libmain.a 0 0 0 184 192 376
libnewlib.a 148 252 870 563 84 1917
libsoc.a 0 0 3181 0 489 3670
libspi_flash.a 36 323 5740 626 1521 8246
libvfs.a 4 44 445 1355 385 2233
Code: Select all
$ make size-files
...
Per-file contributions to ELF file:
Object File DRAM .data & .bss IRAM Flash code & rodata Total
libc.a
lib_a-assert.o 0 0 0 68 60 128
lib_a-dtoa.o 0 0 0 3342 15 3357
lib_a-errno.o 0 0 0 10 0 10
lib_a-fiprintf.o 0 0 0 84 0 84
lib_a-flags.o 0 0 0 127 0 127
lib_a-fopen.o 0 0 0 228 0 228
lib_a-fseek.o 0 0 0 45 0 45
lib_a-fseeko.o 0 0 0 870 0 870
lib_a-mprec.o 0 0 0 2134 296 2430
lib_a-printf.o 0 0 0 116 0 116
lib_a-puts.o 0 0 0 174 16 190
lib_a-reent.o 0 0 0 232 0 232
lib_a-s_frexp.o 0 0 0 110 0 110
lib_a-sprintf.o 0 0 0 0 0 0
lib_a-svfiprintf.o 0 0 0 9642 1210 10852
lib_a-svfprintf.o 0 0 0 0 0 0
lib_a-vfiprintf.o 0 0 0 9981 738 10719
lib_a-vfprintf.o 0 0 0 14173 720 14893
lib_a-vprintf.o 0 0 0 94 0 94
libcxx.a
cxx_guards.o 4 0 0 5 0 9
libdriver.a
gpio.o 4 0 0 0 0 4
periph_ctrl.o 4 0 0 0 0 4
...
Some Notes
- Output shown above is different from running xtensa-esp32-elf-size libcomponent.a or xtensa-esp32-elf-size file.o. xtensa-esp32-elf-size gives you the size of the entire contents of the unlinked library archive or object file. Whereas the output shown above counts only the parts that were actually linked into the final executable (usually much smaller).
- The available IRAM/DRAM estimates and the available dynamic heap memory at runtime will be a little different. There is some accounting overhead from the heap data structures themselves. Plus the WiFi library, TCP/IP library, etc. all make use of dynamic heap memory.
- The size of each section in the .ELF file will be larger than the sum of all the sizes shown above, because of padding.
- Any external PSRAM is not accounted for. (PSRAM can't be used as static memory, only as dynamic heap memory.)
- There are some more features coming in v3.0 to make it easier to analyze dynamic heap memory usage, as well.
- If you find any bugs, please let us know.