Espressif ESP32-S2 Programming Manual page 999

Table of Contents

Advertisement

Chapter 2. API Reference
• ccount 0x... is the CCOUNT (CPU cycle count) register value when the allocation was mode. Is different
for CPU 0 vs CPU 1.
• caller 0x... gives the call stack of the call to malloc()/free(), as a list of PC addresses. These can be
decoded to source files and line numbers, as shown above.
The depth of the call stack recorded for each trace entry can be configured in the project configuration menu, under
Heap Memory Debugging -> Enable heap tracing -> Heap tracing stack depth. Up to 10
stack frames can be recorded for each allocation (the default is 2). Each additional stack frame increases the memory
usage of each heap_trace_record_t record by eight bytes.
Finally, the total number of 'leaked'bytes (bytes allocated but not freed while trace was running) is printed, and
the total number of allocations this represents.
A warning will be printed if the trace buffer was not large enough to hold all the allocations which happened. If you
see this warning, consider either shortening the tracing period or increasing the number of records in the trace buffer.
Host-Based Mode
Once you've identified the code which you think is leaking:
• In the project configuration menu, navigate to Component settings -> Heap Memory Debugging
->
CONFIG_HEAP_TRACING_DEST
• In the project configuration menu, navigate to Component settings -> Application Level Trac-
ing ->
CONFIG_APPTRACE_DESTINATION
• In the project configuration menu, navigate to Component settings -> Application Level Trac-
ing -> FreeRTOS SystemView Tracing and enable CONFIG_APPTRACE_SV_ENABLE.
• Call the function
heap_trace_init_tohost()
module.
• Call the function
heap_trace_start()
immediately before the piece of code which you suspect is leaking memory. In host-based mode argument to
this function is ignored and heap tracing module behaves like HEAP_TRACE_ALL was passed: all allocations
and deallocations are sent to the host.
• Call the function
heap_trace_stop()
cuting.
An example:
#include "esp_heap_trace.h"
...
void app_main()
{
...
ESP_ERROR_CHECK( heap_trace_init_tohost() );
...
}
void some_function()
{
ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
do_something_you_suspect_is_leaking();
ESP_ERROR_CHECK( heap_trace_stop() );
...
}
To gather and analyse heap trace do the following on the host:
1. Build the program and download it to the target as described in
2. Run OpenOCD (see
Espressif Systems
and select Host-Based.
and select Trace memory.
to begin recording all mallocs/frees in the system. Call this
to stop the trace once the suspect piece of code has finished exe-
JTAG
Debugging).
Submit Document Feedback
early in the program, to initialize JTAG heap tracing
Getting Started
988
Guide.
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF