[FL-1517] Maximum heap block stat for os_info cli cmd. (#564)
* 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: あく <alleteam@gmail.com>
This commit is contained in:
		@@ -354,13 +354,10 @@ void cli_command_gpio_set(Cli* cli, string_t args, void* context) {
 | 
				
			|||||||
    return;
 | 
					    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;
 | 
					    const uint8_t threads_num_max = 32;
 | 
				
			||||||
    osThreadId_t threads_id[threads_num_max];
 | 
					    osThreadId_t threads_id[threads_num_max];
 | 
				
			||||||
    uint8_t thread_num = osThreadEnumerate(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("%d threads in total:\r\n", thread_num);
 | 
				
			||||||
    printf("%-20s %-14s %-14s %s\r\n", "Name", "Stack start", "Stack alloc", "Stack free");
 | 
					    printf("%-20s %-14s %-14s %s\r\n", "Name", "Stack start", "Stack alloc", "Stack free");
 | 
				
			||||||
    for(uint8_t i = 0; i < thread_num; i++) {
 | 
					    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),
 | 
					            (uint32_t)(tcb->pxEndOfStack - tcb->pxStack + 1) * sizeof(uint32_t),
 | 
				
			||||||
            osThreadGetStackSpace(threads_id[i]) * 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) {
 | 
					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, "vibro", cli_command_vibro, NULL);
 | 
				
			||||||
    cli_add_command(cli, "led", cli_command_led, 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, "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);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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) {
 | 
					void* pvPortMalloc(size_t xWantedSize) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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);
 | 
					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
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user