Chapter 2. API Reference
esp_err_t heap_trace_init_standalone(heap_trace_record_t *record_buffer, size_t num_records)
Initialise heap tracing in standalone mode.
This function must be called before any other heap tracing functions.
To disable heap tracing and allow the buffer to be freed, stop tracing and then call
heap_trace_init_standalone(NULL, 0);
Return
• ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig.
• ESP_ERR_INVALID_STATE Heap tracing is currently in progress.
• ESP_OK Heap tracing initialised successfully.
Parameters
• record_buffer: Provide a buffer to use for heap trace data. Must remain valid any time heap
tracing is enabled, meaning it must be allocated from internal memory not in PSRAM.
• num_records: Size of the heap trace buffer, as number of record structures.
esp_err_t heap_trace_init_tohost(void)
Initialise heap tracing in host-based mode.
This function must be called before any other heap tracing functions.
Return
• ESP_ERR_INVALID_STATE Heap tracing is currently in progress.
• ESP_OK Heap tracing initialised successfully.
esp_err_t heap_trace_start(heap_trace_mode_t mode)
Start heap tracing. All heap allocations & frees will be traced, until heap_trace_stop() is called.
Note heap_trace_init_standalone() must be called to provide a valid buffer, before this function is called.
Note Calling this function while heap tracing is running will reset the heap trace state and continue tracing.
Return
• ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig.
• ESP_ERR_INVALID_STATE A non-zero-length buffer has not been set via
heap_trace_init_standalone().
• ESP_OK Tracing is started.
Parameters
• mode: Mode for tracing.
– HEAP_TRACE_ALL means all heap allocations and frees are traced.
– HEAP_TRACE_LEAKS means only suspected memory leaks are traced. (When memory is
freed, the record is removed from the trace buffer.)
esp_err_t heap_trace_stop(void)
Stop heap tracing.
Return
• ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig.
• ESP_ERR_INVALID_STATE Heap tracing was not in progress.
• ESP_OK Heap tracing stopped..
esp_err_t heap_trace_resume(void)
Resume heap tracing which was previously stopped.
Unlike heap_trace_start(), this function does not clear the buffer of any pre-existing trace records.
The heap trace mode is the same as when heap_trace_start() was last called (or HEAP_TRACE_ALL if
heap_trace_start() was never called).
Return
• ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig.
• ESP_ERR_INVALID_STATE Heap tracing was already started.
• ESP_OK Heap tracing resumed.
size_t heap_trace_get_count(void)
Return number of records in the heap trace buffer.
It is safe to call this function while heap tracing is running.
Espressif Systems 992
Submit Document Feedback
Release v4.4