From 54114553c1193bcea3c06873ca2121ad375d58de Mon Sep 17 00:00:00 2001 From: SG Date: Mon, 5 Jul 2021 23:01:02 +1000 Subject: [PATCH] [FL-1517] Maximum heap block stat for os_info cli cmd. (#564) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Memmgr: heap_get_max_free_block function. Add "Maximum heap block" to os_info cmd. * Cli: split os_info into ps and free commands Co-authored-by: あく --- applications/cli/cli_commands.c | 15 +++++++++------ core/furi/memmgr_heap.c | 16 ++++++++++++++++ core/furi/memmgr_heap.h | 5 +++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/applications/cli/cli_commands.c b/applications/cli/cli_commands.c index c11c40e9d..2b7c70d0e 100644 --- a/applications/cli/cli_commands.c +++ b/applications/cli/cli_commands.c @@ -354,13 +354,10 @@ void cli_command_gpio_set(Cli* cli, string_t args, void* context) { return; } -void cli_command_os_info(Cli* cli, string_t args, void* context) { +void cli_command_ps(Cli* cli, string_t args, void* context) { const uint8_t threads_num_max = 32; osThreadId_t threads_id[threads_num_max]; uint8_t thread_num = osThreadEnumerate(threads_id, threads_num_max); - - printf("Free HEAP size: %d\r\n", xPortGetFreeHeapSize()); - printf("Minimum heap size: %d\r\n", xPortGetMinimumEverFreeHeapSize()); printf("%d threads in total:\r\n", thread_num); printf("%-20s %-14s %-14s %s\r\n", "Name", "Stack start", "Stack alloc", "Stack free"); for(uint8_t i = 0; i < thread_num; i++) { @@ -372,7 +369,12 @@ void cli_command_os_info(Cli* cli, string_t args, void* context) { (uint32_t)(tcb->pxEndOfStack - tcb->pxStack + 1) * sizeof(uint32_t), osThreadGetStackSpace(threads_id[i]) * sizeof(uint32_t)); } - return; +} + +void cli_command_free(Cli* cli, string_t args, void* context) { + printf("Free heap size: %d\r\n", memmgr_get_free_heap()); + printf("Minimum heap size: %d\r\n", memmgr_get_minimum_free_heap()); + printf("Maximum heap block: %d\r\n", memmgr_heap_get_max_free_block()); } void cli_commands_init(Cli* cli) { @@ -387,5 +389,6 @@ void cli_commands_init(Cli* cli) { cli_add_command(cli, "vibro", cli_command_vibro, NULL); cli_add_command(cli, "led", cli_command_led, NULL); cli_add_command(cli, "gpio_set", cli_command_gpio_set, NULL); - cli_add_command(cli, "os_info", cli_command_os_info, NULL); + cli_add_command(cli, "ps", cli_command_ps, NULL); + cli_add_command(cli, "free", cli_command_free, NULL); } diff --git a/core/furi/memmgr_heap.c b/core/furi/memmgr_heap.c index d8863e427..e0191542e 100644 --- a/core/furi/memmgr_heap.c +++ b/core/furi/memmgr_heap.c @@ -208,6 +208,22 @@ static inline void traceFREE(void* pointer, size_t size) { } } +size_t memmgr_heap_get_max_free_block() { + size_t max_free_size = 0; + BlockLink_t* pxBlock; + osKernelLock(); + + pxBlock = xStart.pxNextFreeBlock; + while(pxBlock->pxNextFreeBlock != NULL) { + if(pxBlock->xBlockSize > max_free_size) { + max_free_size = pxBlock->xBlockSize; + } + pxBlock = pxBlock->pxNextFreeBlock; + } + + osKernelUnlock(); + return max_free_size; +} /*-----------------------------------------------------------*/ void* pvPortMalloc(size_t xWantedSize) { diff --git a/core/furi/memmgr_heap.h b/core/furi/memmgr_heap.h index 23d75107e..d6a2ee90b 100644 --- a/core/furi/memmgr_heap.h +++ b/core/furi/memmgr_heap.h @@ -23,6 +23,11 @@ void memmgr_heap_disable_thread_trace(osThreadId_t thread_id); */ size_t memmgr_heap_get_thread_memory(osThreadId_t thread_id); +/** Memmgr heap get the max contiguous block size on the heap + * @return size_t max contiguous block size + */ +size_t memmgr_heap_get_max_free_block(); + #ifdef __cplusplus } #endif