Espressif ESP32-S2 Programming Manual page 998

Hide thumbs Also See for ESP32-S2:
Table of Contents

Advertisement

Chapter 2. API Reference
• Call the function
heap_trace_start()
immediately before the piece of code which you suspect is leaking memory.
• Call the function
heap_trace_stop()
cuting.
• Call the function
heap_trace_dump()
An example:
#include "esp_heap_trace.h"
#define NUM_RECORDS 100
static heap_trace_record_t trace_record[NUM_RECORDS];
internal RAM
...
void app_main()
{
...
ESP_ERROR_CHECK( heap_trace_init_standalone(trace_record, NUM_RECORDS) );
...
}
void some_function()
{
ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
do_something_you_suspect_is_leaking();
ESP_ERROR_CHECK( heap_trace_stop() );
heap_trace_dump();
...
}
The output from the heap trace will look something like this:
2
allocations trace
32
bytes
(@
0x3ffaf214) allocated CPU
0x400d276d:0x400d27c1
0x400d276d: leak_some_memory at
blink.c:27
0x400d27c1: blink_task at
8
bytes
(@
0x3ffaf804) allocated CPU
0x400d2776:0x400d27c1
0x400d2776: leak_some_memory at
blink.c:29
0x400d27c1: blink_task at
40
bytes
'leaked'
in
total allocations
2
(Above example output is using
The first line indicates how many allocation entries are in the buffer, compared to its total size.
In HEAP_TRACE_LEAKS mode, for each traced memory allocation which has not already been freed a line is printed
with:
• XX bytes is number of bytes allocated
• @ 0x... is the heap address returned from malloc/calloc.
• CPU x is the CPU (0 or 1) running when the allocation was made.
Espressif Systems
to begin recording all mallocs/frees in the system. Call this
to stop the trace once the suspect piece of code has finished exe-
to dump the results of the heap trace.
(100
entry buffer)
0
/path/to/idf/examples/get-started/blink/main/./
/path/to/idf/examples/get-started/blink/main/./blink.c:52
0
ccount
/path/to/idf/examples/get-started/blink/main/./
/path/to/idf/examples/get-started/blink/main/./blink.c:52
trace
(2
allocations)
total frees
0
IDF Monitor
to automatically decode PC addresses to their source files & line number.)
Submit Document Feedback
//
This buffer must be
ccount
0x2e9b7384
caller␣
0x2e9b79c0
caller␣
987
in␣
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