To request heap statistics, a pointer to a heap structure is required. This is straightforward for a user-defined heap. However, such a pointer is not known for heaps created by other components or libraries, like libc. Therefore, it is not possible to calculate the total heap memory. The proposed solution is to use an array of pointers, which is filled in on every sys_heap_init() call. One can then iterate through it to sum up the total memory allocated for all heaps. The array size is configurable. The default array size is zero, which means the feature is disabled. Any other integer greater then zero defines the array size and enables the feature. A list of pointers instead of an array could be another approach, but it requeres a heap, which is not always available. Signed-off-by: Ivan Pankratov <ivan.pankratov@silabs.com> |
||
|---|---|---|
| .. | ||
| src | ||
| CMakeLists.txt | ||
| prj.conf | ||
| README.rst | ||
| sample.yaml | ||
.. zephyr:code-sample:: sys-heap
:name: System heap
Print system heap usage to the console.
Overview
********
A simple sample that can be used with any :ref:`supported board <boards>` and
prints system heap usage to the console.
Building
********
This application can be built on :ref:`native_sim <native_sim>` as follows:
.. zephyr-app-commands::
:zephyr-app: samples/basic/sys_heap
:host-os: unix
:board: native_sim
:goals: build
:compact:
To build for another board, change "native_sim" above to that board's name.
Running
*******
Run build/zephyr/zephyr.exe
Sample Output
*************
.. code-block:: console
System heap sample
allocated 0, free 196, max allocated 0, heap size 256
allocated 156, free 36, max allocated 156, heap size 256
allocated 100, free 92, max allocated 156, heap size 256
allocated 0, free 196, max allocated 156, heap size 256