From 4922c64d433ebeb31202c9acfb60ba1ac8d0d4e1 Mon Sep 17 00:00:00 2001 From: esp Date: Tue, 17 Dec 2024 16:24:58 +0530 Subject: [PATCH] esp32: add freertos task related diagnostics to platform --- src/platform/ESP32/ESP32Utils.cpp | 44 +++---------------------------- src/platform/ESP32/ESP32Utils.h | 3 +-- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/src/platform/ESP32/ESP32Utils.cpp b/src/platform/ESP32/ESP32Utils.cpp index 5fc9179541aed6..07b99f0ef0d5d3 100644 --- a/src/platform/ESP32/ESP32Utils.cpp +++ b/src/platform/ESP32/ESP32Utils.cpp @@ -37,11 +37,14 @@ #ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE #include "esp_heap_caps.h" +#include +#include #include #include #include using namespace chip::DeviceLayer; +using namespace ::chip::Platform; #endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE using namespace ::chip::DeviceLayer::Internal; @@ -235,7 +238,6 @@ const char * ESP32Utils::WiFiModeToStr(wifi_mode_t wifiMode) } } -#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE const char * ESP32Utils::WiFiDisconnectReasonToStr(uint16_t reason) { switch (reason) @@ -287,44 +289,6 @@ const char * ESP32Utils::WiFiDisconnectReasonToStr(uint16_t reason) } } -void LogHeapDataCallback(chip::System::Layer * systemLayer, void * appState) -{ - // Internal RAM (default heap) - uint32_t internal_free = heap_caps_get_free_size(MALLOC_CAP_INTERNAL); - uint32_t internal_largest_free_block = heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL); - uint32_t internal_min_free = heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL); - - MATTER_LOG_METRIC(chip::Tracing::kMetricHeapInternalFree, internal_free); - MATTER_LOG_METRIC(chip::Tracing::kMetricHeapInternalMinFree, internal_min_free); - MATTER_LOG_METRIC(chip::Tracing::kMetricHeapInternalLargestBlock, internal_largest_free_block); - -#ifdef CONFIG_SPIRAM - // External RAM (if PSRAM is enabled) - uint32_t external_free = heap_caps_get_free_size(MALLOC_CAP_SPIRAM); - uint32_t external_largest_free_block = heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM); - uint32_t external_min_free = heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM); - - MATTER_LOG_METRIC(chip::Tracing::kMetricHeapExternalFree, external_free); - MATTER_LOG_METRIC(chip::Tracing::kMetricHeapExternalMinFree, external_min_free); - MATTER_LOG_METRIC(chip::Tracing::kMetricHeapExternalLargestBlock, external_largest_free_block); -#endif - - // Reschedule the timer for the next interval - systemLayer->StartTimer(chip::System::Clock::Milliseconds32(CONFIG_HEAP_LOG_INTERVAL), LogHeapDataCallback, nullptr); -} - -// Function to initialize and start periodic heap logging -void ESP32Utils::LogHeapInfo() -{ - // Log immediately - LogHeapDataCallback(&SystemLayer(), nullptr); - - // Start the periodic logging using SystemLayer - SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(CONFIG_HEAP_LOG_INTERVAL), LogHeapDataCallback, nullptr); -} - -#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE - struct netif * ESP32Utils::GetStationNetif(void) { return GetNetif(kDefaultWiFiStationNetifKey); @@ -516,7 +480,7 @@ void ESP32Utils::LogHeapInfo() { ESP_LOGE(TAG, "Failed to register callback. Error: 0x%08x", err); } - // Log immediately + LogHeapDataCallback(&SystemLayer(), nullptr); // Start the periodic logging using SystemLayer diff --git a/src/platform/ESP32/ESP32Utils.h b/src/platform/ESP32/ESP32Utils.h index c0ae80e55c7346..7c93236fd2daee 100644 --- a/src/platform/ESP32/ESP32Utils.h +++ b/src/platform/ESP32/ESP32Utils.h @@ -48,10 +48,9 @@ class ESP32Utils static CHIP_ERROR ClearWiFiStationProvision(void); static CHIP_ERROR InitWiFiStack(void); -#ifdef CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE static const char * WiFiDisconnectReasonToStr(uint16_t reason); static void LogHeapInfo(); -#endif // CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE + static CHIP_ERROR LogTaskSnapshotInfo(); static CHIP_ERROR MapError(esp_err_t error); static void RegisterESP32ErrorFormatter();