Optimization Toolsï
The available optimization tools let you analyse Footprint and Memory Usage and Data Structures using different build system targets.
Footprint and Memory Usageï
The build system offers 3 targets to view and analyse RAM, ROM and stack usage in generated images. The tools run on the final image and give information about size of symbols and code being used in both RAM and ROM. Additionally, with features available through the compiler, we can also generate worst-case stack usage analysis.
Some of the tools mentioned in this section are organizing their output based on the physical organization of the symbols. As some symbols might be external to the projectâs tree structure, or might lack metadata needed to display them by name, the following top-level containers are used to group such symbols:
Hidden - The RAM and ROM reports list all processing symbols with no matching mapped files in the Hidden category.
This means that the file for the listed symbol was not added to the metadata file, was empty, or was undefined. The tool was unable to get the name of the function for the given symbol nor identify where it comes from.
No paths - The RAM and ROM reports list all processing symbols with relative paths in the No paths category.
This means that the listed symbols cannot be placed in the tree structure of the report at an absolute path under one specific file. The tool was able to get the name of the function, but it was unable to identify where it comes from.
Note
You can have multiple cases of the same function, and the No paths category will list the sum of these in one entry.
Build Target: ram_reportï
List all compiled objects and their RAM usage in a tabular form with bytes per symbol and the percentage it uses. The data is grouped based on the file system location of the object in the tree and the file containing the symbol.
Use the ram_report target with your board, as in the following example.
If you are using Sysbuild (System build), see Dedicated image build targets instead.
Using west:
# From the root of the zephyr repository
west build -b reel_board samples/hello_world
west build -t ram_report
Using CMake and ninja:
# From the root of the zephyr repository
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board samples/hello_world
# Now run the build tool on the generated build system:
ninja -Cbuild ram_report
These commands will generate something similar to the output below:
Path Size % Address
========================================================================================
Root 4637 100.00% -
âââ (hidden) 4 0.09% -
âââ (no paths) 2748 59.26% -
â âââ _cpus_active 4 0.09% 0x20000314
â âââ _kernel 32 0.69% 0x20000318
â âââ _sw_isr_table 384 8.28% 0x00006474
â âââ cli.1 16 0.35% 0x20000254
â âââ on.2 4 0.09% 0x20000264
â âââ poll_out_lock.0 4 0.09% 0x200002d4
â âââ z_idle_threads 128 2.76% 0x20000120
â âââ z_interrupt_stacks 2048 44.17% 0x20000360
â âââ z_main_thread 128 2.76% 0x200001a0
âââ WORKSPACE 184 3.97% -
â âââ modules 184 3.97% -
â âââ hal 184 3.97% -
â âââ nordic 184 3.97% -
â âââ nrfx 184 3.97% -
â âââ drivers 184 3.97% -
â âââ src 184 3.97% -
â âââ nrfx_clock.c 8 0.17% -
â â âââ m_clock_cb 8 0.17% 0x200002e4
â âââ nrfx_gpiote.c 132 2.85% -
â â âââ m_cb 132 2.85% 0x20000060
â âââ nrfx_ppi.c 4 0.09% -
â â âââ m_channels_allocated 4 0.09% 0x200000e4
â âââ nrfx_twim.c 40 0.86% -
â âââ m_cb 40 0.86% 0x200002ec
âââ ZEPHYR_BASE 1701 36.68% -
âââ arch 5 0.11% -
â âââ arm 5 0.11% -
â âââ core 5 0.11% -
â âââ mpu 1 0.02% -
â â âââ arm_mpu.c 1 0.02% -
â â âââ static_regions_num 1 0.02% 0x20000348
â âââ tls.c 4 0.09% -
â âââ z_arm_tls_ptr 4 0.09% 0x20000240
âââ drivers 258 5.56% -
â âââ ... ... ...%
========================================================================================
4637
Build Target: rom_reportï
List all compiled objects and their ROM usage in a tabular form with bytes per symbol and the percentage it uses. The data is grouped based on the file system location of the object in the tree and the file containing the symbol.
Use the rom_report target with your board, as in the following example.
If you are using Sysbuild (System build), see Dedicated image build targets instead.
Using west:
# From the root of the zephyr repository
west build -b reel_board samples/hello_world
west build -t rom_report
Using CMake and ninja:
# From the root of the zephyr repository
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board samples/hello_world
# Now run the build tool on the generated build system:
ninja -Cbuild rom_report
These commands will generate something similar to the output below:
Path Size % Address
========================================================================================
Root 27828 100.00% -
âââ ... ... ...%
âââ ZEPHYR_BASE 13558 48.72% -
âââ arch 1766 6.35% -
â âââ arm 1766 6.35% -
â âââ core 1766 6.35% -
â âââ cortex_m 1020 3.67% -
â â âââ fault.c 620 2.23% -
â â â âââ bus_fault.constprop.0 108 0.39% 0x00000749
â â â âââ mem_manage_fault.constprop.0 120 0.43% 0x000007b5
â â â âââ usage_fault.constprop.0 84 0.30% 0x000006f5
â â â âââ z_arm_fault 292 1.05% 0x0000082d
â â â âââ z_arm_fault_init 16 0.06% 0x00000951
â â âââ ... ... ...%
âââ boards 32 0.11% -
â âââ arm 32 0.11% -
â âââ reel_board 32 0.11% -
â âââ board.c 32 0.11% -
â âââ __init_board_reel_board_init 8 0.03% 0x000063e4
â âââ board_reel_board_init 24 0.09% 0x00000ed5
âââ build 194 0.70% -
â âââ zephyr 194 0.70% -
â âââ isr_tables.c 192 0.69% -
â â âââ _irq_vector_table 192 0.69% 0x00000040
â âââ misc 2 0.01% -
â âââ generated 2 0.01% -
â âââ configs.c 2 0.01% -
â âââ _ConfigAbsSyms 2 0.01% 0x00005945
âââ drivers 6282 22.57% -
â âââ ... ... ...%
========================================================================================
21652
Build Targets: ram_plot/rom_plotï
Similar to the ram_report and rom_report build targets, these targets generate memory usage
reports in a sunburst chart as a visual representation.
A user can click on segments to navigate through the directory structures, and hover over segments
to get more details.
Running the targets will first generate the CLI report and then open a browser window.
Using west:
# From the root of the zephyr repository
west build -b reel_board samples/hello_world
west build -t ram_plot
Using CMake and ninja:
# From the root of the zephyr repository
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board samples/hello_world
# Now run the build tool on the generated build system:
ninja -Cbuild ram_plot
And similarly for the ROM usage.
Using west:
# From the root of the zephyr repository
west build -b reel_board samples/hello_world
west build -t rom_plot
Using CMake and ninja:
# From the root of the zephyr repository
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board samples/hello_world
# Now run the build tool on the generated build system:
ninja -Cbuild rom_plot
Build Target: puncoverï
This target uses a third-party tool called puncover which can be found at https://github.com/HBehrens/puncover. When this target is built, it will launch a local web server which will allow you to open a web client and browse the files and view their ROM, RAM, and stack usage.
Before you can use this target, install the puncover Python module:
pip3 install --user puncover
Warning
This is a third-party tool that might or might not be working at any given time. Please check the GitHub issues, and report new problems to the project maintainer.
After you installed the Python module, use puncover target with your board,
as in the following example.
If you are using Sysbuild (System build), see Dedicated image build targets instead.
Using west:
# From the root of the zephyr repository
west build -b reel_board samples/hello_world
west build -t puncover
Using CMake and ninja:
# From the root of the zephyr repository
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board samples/hello_world
# Now run the build tool on the generated build system:
ninja -Cbuild puncover
The puncover target will start a local web server on localhost:5000 by default.
The host IP and port the HTTP server runs on can be changed by setting the environment
variables PUNCOVER_HOST and PUNCOVER_PORT.
To view worst-case stack usage analysis, build this with the
CONFIG_STACK_USAGE enabled.
Using west:
# From the root of the zephyr repository
west build -b reel_board samples/hello_world -- -DCONFIG_STACK_USAGE=y
west build -t puncover
Using CMake and ninja:
# From the root of the zephyr repository
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board -DCONFIG_STACK_USAGE=y samples/hello_world
# Now run the build tool on the generated build system:
ninja -Cbuild puncover
Data Structuresï
Build Target: paholeï
Poke-a-hole (pahole) is an object-file analysis tool to find the size of the data structures, and the holes caused due to aligning the data elements to the word-size of the CPU by the compiler.
Poke-a-hole (pahole) must be installed prior to using this target. It can be obtained from https://git.kernel.org/pub/scm/devel/pahole/pahole.git and is available in the dwarves package in both fedora and ubuntu:
sudo apt-get install dwarves
Alternatively, you can get it from fedora:
sudo dnf install dwarves
After you installed the package, use pahole target with your board,
as in the following example.
If you are using Sysbuild (System build), see Dedicated image build targets instead.
Using west:
# From the root of the zephyr repository
west build -b reel_board samples/hello_world
west build -t pahole
Using CMake and ninja:
# From the root of the zephyr repository
# Use cmake to configure a Ninja-based buildsystem:
cmake -Bbuild -GNinja -DBOARD=reel_board samples/hello_world
# Now run the build tool on the generated build system:
ninja -Cbuild pahole
Pahole will generate something similar to the output below in the console:
/* Used at: [...]/build/zephyr/kobject_hash.c */
/* <375> [...]/zephyr/include/zephyr/sys/dlist.h:37 */
union {
struct _dnode * head; /* 0 4 */
struct _dnode * next; /* 0 4 */
};
/* Used at: [...]/build/zephyr/kobject_hash.c */
/* <397> [...]/zephyr/include/zephyr/sys/dlist.h:36 */
struct _dnode {
union {
struct _dnode * head; /* 0 4 */
struct _dnode * next; /* 0 4 */
}; /* 0 4 */
union {
struct _dnode * tail; /* 4 4 */
struct _dnode * prev; /* 4 4 */
}; /* 4 4 */
/* size: 8, cachelines: 1, members: 2 */
/* last cacheline: 8 bytes */
};
/* Used at: [...]/build/zephyr/kobject_hash.c */
/* <3b7> [...]/zephyr/include/zephyr/sys/dlist.h:41 */
union {
struct _dnode * tail; /* 0 4 */
struct _dnode * prev; /* 0 4 */
};
...
...