2021-05-02 22:15:17 -04:00
|
|
|
/*
|
2022-12-08 03:47:02 -05:00
|
|
|
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
2021-05-02 22:15:17 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2018-12-12 12:35:17 -05:00
|
|
|
#include <sdkconfig.h>
|
|
|
|
|
|
|
|
#define HEAP_TRACE_SRCFILE /* don't warn on inclusion here */
|
|
|
|
#include "esp_heap_trace.h"
|
|
|
|
#undef HEAP_TRACE_SRCFILE
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
#if CONFIG_APPTRACE_SV_ENABLE
|
2018-12-12 12:35:17 -05:00
|
|
|
#include "esp_app_trace.h"
|
|
|
|
#include "esp_sysview_trace.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STACK_DEPTH CONFIG_HEAP_TRACING_STACK_DEPTH
|
|
|
|
|
|
|
|
#ifdef CONFIG_HEAP_TRACING_TOHOST
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
#if !CONFIG_APPTRACE_SV_ENABLE
|
2018-12-12 12:35:17 -05:00
|
|
|
#error None of the heap tracing backends is enabled! You must enable SystemView compatible tracing to use this feature.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static bool s_tracing;
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
esp_err_t heap_trace_init_tohost(void)
|
2018-12-12 12:35:17 -05:00
|
|
|
{
|
|
|
|
if (s_tracing) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t heap_trace_start(heap_trace_mode_t mode_param)
|
|
|
|
{
|
2020-12-21 12:17:42 -05:00
|
|
|
#if CONFIG_APPTRACE_SV_ENABLE
|
2018-12-12 12:35:17 -05:00
|
|
|
esp_err_t ret = esp_sysview_heap_trace_start((uint32_t)-1);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
s_tracing = true;
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t heap_trace_stop(void)
|
|
|
|
{
|
|
|
|
esp_err_t ret = ESP_ERR_NOT_SUPPORTED;
|
2020-12-21 12:17:42 -05:00
|
|
|
#if CONFIG_APPTRACE_SV_ENABLE
|
2018-12-12 12:35:17 -05:00
|
|
|
ret = esp_sysview_heap_trace_stop();
|
|
|
|
#endif
|
|
|
|
s_tracing = false;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t heap_trace_resume(void)
|
|
|
|
{
|
|
|
|
return heap_trace_start(HEAP_TRACE_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t heap_trace_get_count(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t heap_trace_get(size_t index, heap_trace_record_t *record)
|
|
|
|
{
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2022-12-08 03:47:02 -05:00
|
|
|
esp_err_t heap_trace_summary(heap_trace_summary_t *summary)
|
|
|
|
{
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2018-12-12 12:35:17 -05:00
|
|
|
void heap_trace_dump(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-09 07:21:37 -05:00
|
|
|
void heap_trace_dump_caps(__attribute__((unused)) const uint32_t caps)
|
2022-12-08 03:47:02 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-12 12:35:17 -05:00
|
|
|
/* Add a new allocation to the heap trace records */
|
|
|
|
static IRAM_ATTR void record_allocation(const heap_trace_record_t *record)
|
|
|
|
{
|
|
|
|
if (!s_tracing) {
|
|
|
|
return;
|
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
#if CONFIG_APPTRACE_SV_ENABLE
|
2018-12-12 12:35:17 -05:00
|
|
|
esp_sysview_heap_trace_alloc(record->address, record->size, record->alloced_by);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* record a free event in the heap trace log
|
|
|
|
|
|
|
|
For HEAP_TRACE_ALL, this means filling in the freed_by pointer.
|
|
|
|
For HEAP_TRACE_LEAKS, this means removing the record from the log.
|
|
|
|
*/
|
|
|
|
static IRAM_ATTR void record_free(void *p, void **callers)
|
|
|
|
{
|
|
|
|
if (!s_tracing) {
|
|
|
|
return;
|
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
#if CONFIG_APPTRACE_SV_ENABLE
|
2018-12-12 12:35:17 -05:00
|
|
|
esp_sysview_heap_trace_free(p, callers);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "heap_trace.inc"
|
|
|
|
|
|
|
|
#endif /*CONFIG_HEAP_TRACING_TOHOST*/
|