From c39a9de3441e3bdcaf080b6e11a68d208c5ee588 Mon Sep 17 00:00:00 2001 From: Guillaume Souchere Date: Fri, 9 Dec 2022 13:21:37 +0100 Subject: [PATCH] heap_trace: unify API to pass caps param to heap_trace_dump() --- components/app_trace/heap_trace_tohost.c | 7 +------ components/heap/heap_trace_standalone.c | 23 +++++++++-------------- components/heap/include/esp_heap_trace.h | 21 ++++++--------------- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/components/app_trace/heap_trace_tohost.c b/components/app_trace/heap_trace_tohost.c index 0e8567cbc7..fb19aea6f1 100644 --- a/components/app_trace/heap_trace_tohost.c +++ b/components/app_trace/heap_trace_tohost.c @@ -79,12 +79,7 @@ void heap_trace_dump(void) return; } -void heap_trace_dump_internal_ram(void) -{ - return; -} - -void heap_trace_dump_psram(void) +void heap_trace_dump_caps(__attribute__((unused)) const uint32_t caps) { return; } diff --git a/components/heap/heap_trace_standalone.c b/components/heap/heap_trace_standalone.c index a7b318109f..c78f3b3c91 100644 --- a/components/heap/heap_trace_standalone.c +++ b/components/heap/heap_trace_standalone.c @@ -13,6 +13,7 @@ #include "esp_attr.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#include "esp_memory_utils.h" #define STACK_DEPTH CONFIG_HEAP_TRACING_STACK_DEPTH @@ -156,16 +157,12 @@ esp_err_t heap_trace_summary(heap_trace_summary_t *summary) return ESP_OK; } -void heap_trace_dump_internal_ram(void) { - heap_trace_dump_base(true, false); -} - -void heap_trace_dump_psram(void) { - heap_trace_dump_base(false, true); -} - void heap_trace_dump(void) { - heap_trace_dump_base(true, true); + heap_trace_dump_caps(MALLOC_CAP_INTERNAL | MALLOC_CAP_SPIRAM); +} + +void heap_trace_dump_caps(const uint32_t caps) { + heap_trace_dump_base(caps & MALLOC_CAP_INTERNAL, caps & MALLOC_CAP_SPIRAM); } static void heap_trace_dump_base(bool internal_ram, bool psram) @@ -309,11 +306,9 @@ static IRAM_ATTR void record_free(void *p, void **callers) /* search backwards for the allocation record matching this free */ int i = -1; - if (records.count > 0) { - for (i = records.count - 1; i >= 0; i--) { - if (records.buffer[i].address == p) { - break; - } + for (i = records.count - 1; i >= 0; i--) { + if (records.buffer[i].address == p) { + break; } } diff --git a/components/heap/include/esp_heap_trace.h b/components/heap/include/esp_heap_trace.h index 6d66f4ab4c..81ac813303 100644 --- a/components/heap/include/esp_heap_trace.h +++ b/components/heap/include/esp_heap_trace.h @@ -155,23 +155,14 @@ esp_err_t heap_trace_get(size_t index, heap_trace_record_t *record); void heap_trace_dump(void); /** - * @brief Same as heap_trace_dump() but will only log allocations in Internal-RAM + * @brief Dump heap trace from the memory of the capabilities passed as parameter. * - * @note It is safe to call this function while heap tracing is - * running, however in HEAP_TRACE_LEAK mode the dump may skip - * entries unless heap tracing is stopped first. + * @param caps Capability(ies) of the memory from which to dump the trace. + * Set MALLOC_CAP_INTERNAL to dump heap trace data from internal memory. + * Set MALLOC_CAP_SPIRAM to dump heap trace data from PSRAM. + * Set both to dump both heap trace data. */ -void heap_trace_dump_internal_ram(void); - -/** - * @brief Same as heap_trace_dump() but will only log allocations in PSRAM - * - * @note It is safe to call this function while heap tracing is - * running, however in HEAP_TRACE_LEAK mode the dump may skip - * entries unless heap tracing is stopped first. - */ -void heap_trace_dump_psram(void); - +void heap_trace_dump_caps(const uint32_t caps); /** * @brief Get summary information about the result of a heap trace