[FL-1107] OS CLI command for threads info listing (#405)
* cli_commands: add os_info command for threads info listing * cli_commands: add total and minimal heap size in os_info * common-api: add task control block type * cli: print thread allocated stack size * CLI: convert free stack size to bytes in os_info command Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
616b7325c6
commit
eae9cb3514
@ -2,6 +2,7 @@
|
||||
#include <api-hal.h>
|
||||
#include <api-hal-gpio.h>
|
||||
#include <rtc.h>
|
||||
#include <task-control-block.h>
|
||||
|
||||
void cli_command_help(string_t args, void* context) {
|
||||
(void)args;
|
||||
@ -183,6 +184,27 @@ void cli_command_gpio_set(string_t args, void* context) {
|
||||
return;
|
||||
}
|
||||
|
||||
void cli_command_os_info(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++) {
|
||||
TaskControlBlock* tcb = (TaskControlBlock*)threads_id[i];
|
||||
printf(
|
||||
"%-20s 0x%-12lx %-14ld %ld\r\n",
|
||||
osThreadGetName(threads_id[i]),
|
||||
(uint32_t)tcb->pxStack,
|
||||
(uint32_t)(tcb->pxEndOfStack - tcb->pxStack + 1) * sizeof(uint32_t),
|
||||
osThreadGetStackSpace(threads_id[i]) * sizeof(uint32_t));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cli_commands_init(Cli* cli) {
|
||||
cli_add_command(cli, "help", cli_command_help, cli);
|
||||
cli_add_command(cli, "?", cli_command_help, cli);
|
||||
@ -194,4 +216,5 @@ void cli_commands_init(Cli* cli) {
|
||||
cli_add_command(cli, "vibro", cli_command_vibro, cli);
|
||||
cli_add_command(cli, "led", cli_command_led, cli);
|
||||
cli_add_command(cli, "gpio_set", cli_command_gpio_set, cli);
|
||||
cli_add_command(cli, "os_info", cli_command_os_info, cli);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)131072)
|
||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
#define configUSE_TRACE_FACILITY 0
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configQUEUE_REGISTRY_SIZE 8
|
||||
|
@ -72,7 +72,7 @@
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)131072)
|
||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
#define configUSE_TRACE_FACILITY 0
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configQUEUE_REGISTRY_SIZE 8
|
||||
|
80
lib/common-api/task-control-block.h
Normal file
80
lib/common-api/task-control-block.h
Normal file
@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
|
||||
typedef struct /* The old naming convention is used to prevent breaking kernel aware debuggers. */
|
||||
{
|
||||
volatile StackType_t *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */
|
||||
|
||||
#if ( portUSING_MPU_WRAPPERS == 1 )
|
||||
xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */
|
||||
#endif
|
||||
|
||||
ListItem_t xStateListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */
|
||||
ListItem_t xEventListItem; /*< Used to reference a task from an event list. */
|
||||
UBaseType_t uxPriority; /*< The priority of the task. 0 is the lowest priority. */
|
||||
StackType_t *pxStack; /*< Points to the start of the stack. */
|
||||
char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
|
||||
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
|
||||
StackType_t *pxEndOfStack; /*< Points to the highest valid address for the stack. */
|
||||
#endif
|
||||
|
||||
#if ( portCRITICAL_NESTING_IN_TCB == 1 )
|
||||
UBaseType_t uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
UBaseType_t uxTCBNumber; /*< Stores a number that increments each time a TCB is created. It allows debuggers to determine when a task has been deleted and then recreated. */
|
||||
UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_MUTEXES == 1 )
|
||||
UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */
|
||||
UBaseType_t uxMutexesHeld;
|
||||
#endif
|
||||
|
||||
#if ( configUSE_APPLICATION_TASK_TAG == 1 )
|
||||
TaskHookFunction_t pxTaskTag;
|
||||
#endif
|
||||
|
||||
#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
|
||||
void *pvThreadLocalStoragePointers[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];
|
||||
#endif
|
||||
|
||||
#if( configGENERATE_RUN_TIME_STATS == 1 )
|
||||
uint32_t ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_NEWLIB_REENTRANT == 1 )
|
||||
/* Allocate a Newlib reent structure that is specific to this task.
|
||||
Note Newlib support has been included by popular demand, but is not
|
||||
used by the FreeRTOS maintainers themselves. FreeRTOS is not
|
||||
responsible for resulting newlib operation. User must be familiar with
|
||||
newlib and must provide system-wide implementations of the necessary
|
||||
stubs. Be warned that (at the time of writing) the current newlib design
|
||||
implements a system-wide malloc() that must be provided with locks. */
|
||||
struct _reent xNewLib_reent;
|
||||
#endif
|
||||
|
||||
#if( configUSE_TASK_NOTIFICATIONS == 1 )
|
||||
volatile uint32_t ulNotifiedValue;
|
||||
volatile uint8_t ucNotifyState;
|
||||
#endif
|
||||
|
||||
/* See the comments in FreeRTOS.h with the definition of
|
||||
tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */
|
||||
#if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */
|
||||
uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */
|
||||
#endif
|
||||
|
||||
#if( INCLUDE_xTaskAbortDelay == 1 )
|
||||
uint8_t ucDelayAborted;
|
||||
#endif
|
||||
|
||||
#if( configUSE_POSIX_ERRNO == 1 )
|
||||
int iTaskErrno;
|
||||
#endif
|
||||
|
||||
} TaskControlBlock;
|
Loading…
Reference in New Issue
Block a user