From fb29462e73ae922543b756a350d248eb5be9b39b Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 13 Nov 2019 09:12:23 -0600 Subject: [PATCH] add heap frag logging to esp32 --- WiFiManager.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 0c91b70..b62ab09 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2456,11 +2456,24 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { uint32_t free; uint16_t max; uint8_t frag; + #ifdef ESP8266 ESP.getHeapStats(&free, &max, &frag); + _debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag); + #elif defined ESP32 + // total_free_bytes; ///< Total free bytes in the heap. Equivalent to multi_free_heap_size(). + // total_allocated_bytes; ///< Total bytes allocated to data in the heap. + // largest_free_block; ///< Size of largest free block in the heap. This is the largest malloc-able size. + // minimum_free_bytes; ///< Lifetime minimum free heap size. Equivalent to multi_minimum_free_heap_size(). + // allocated_blocks; ///< Number of (variable size) blocks allocated in the heap. + // free_blocks; ///< Number of (variable size) free blocks in the heap. + // total_blocks; ///< Total number of (variable size) blocks in the heap. + multi_heap_info_t info; + heap_caps_get_info(&info, MALLOC_CAP_INTERNAL); + free = info.total_free_bytes; + max = info.largest_free_block; + frag = 100 - (max * 100) / free; _debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag); - // _debugPort.print((String)ESP.getFreeHeap()); - // _debugPort.print((String)ESP.getMaxFreeBlockSize()); - // _debugPort.print((String)ESP.getHeapFragmentation()); + #endif } _debugPort.print("*WM: "); if(_debugLevel == DEBUG_DEV) _debugPort.print("["+(String)level+"] ");