From dccdacae426f699405da195f7d6ddb283a12e632 Mon Sep 17 00:00:00 2001 From: dario Date: Tue, 21 Nov 2023 21:47:58 +0100 Subject: [PATCH] Added STA_DEBUG_HEAP_STATS for debugging --- include/sta/rtos/debug/heap_stats.hpp | 29 +++++++++++++++++++++++++ src/debug/heap_stats.cpp | 31 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 include/sta/rtos/debug/heap_stats.hpp create mode 100644 src/debug/heap_stats.cpp diff --git a/include/sta/rtos/debug/heap_stats.hpp b/include/sta/rtos/debug/heap_stats.hpp new file mode 100644 index 0000000..fe1cbd5 --- /dev/null +++ b/include/sta/rtos/debug/heap_stats.hpp @@ -0,0 +1,29 @@ +/* + * heap_stats.hpp + * + * Created on: Nov 21, 2023 + * Author: Dario + */ + +#ifndef RTOS_DEBUG_HEAP_STATS_HPP +#define RTOS_DEBUG_HEAP_STATS_HPP + +#include +#ifdef STA_DEBUGGING_ENABLED + +#include + +void printHeapStats(); + +/** + * @brief Print the current heap stats. + */ +# define STA_DEBUG_HEAP_STATS() printHeapStats() + +#else + +# define STA_DEBUG_HEAP_STATS() ((void)0) + +#endif // STA_DEBUGGING_ENABLED + +#endif /* RTOS_DEBUG_HEAP_STATS_HPP */ diff --git a/src/debug/heap_stats.cpp b/src/debug/heap_stats.cpp new file mode 100644 index 0000000..f46fa1a --- /dev/null +++ b/src/debug/heap_stats.cpp @@ -0,0 +1,31 @@ +/* + * heap_stats.cpp + * + * Created on: Nov 21, 2023 + * Author: Dario + */ + +#include + +#ifdef STA_DEBUGGING_ENABLED + +#include +#include + +void printHeapStats() +{ + xHeapStats stats; + vPortGetHeapStats(&stats); + + STA_DEBUG_PRINTF( + "[HEAP STATS] \n Available: %d\n Lowest: %d\n Mallocs: %d\n Frees: %d", + stats.xAvailableHeapSpaceInBytes, + stats.xMinimumEverFreeBytesRemaining, + stats.xNumberOfSuccessfulAllocations, + stats.xNumberOfSuccessfulFrees + ); +} + +#endif // STA_DEBUGGING_ENABLED + +