|
20 | 20 | #include "freertos/FreeRTOS.h" |
21 | 21 | #include "freertos/task.h" |
22 | 22 | #include "soc/rtc_cntl_reg.h" |
| 23 | +#include "sdkconfig.h" |
| 24 | + |
| 25 | +#ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS |
| 26 | +#define WITH_TASKS_INFO 1 |
| 27 | +#endif |
23 | 28 |
|
24 | 29 | static void register_free(); |
25 | 30 | static void register_restart(); |
26 | 31 | static void register_deep_sleep(); |
27 | 32 | static void register_make(); |
| 33 | +#if WITH_TASKS_INFO |
| 34 | +static void register_tasks(); |
| 35 | +#endif |
28 | 36 |
|
29 | 37 | void register_system() |
30 | 38 | { |
31 | 39 | register_free(); |
32 | 40 | register_restart(); |
33 | 41 | register_deep_sleep(); |
34 | 42 | register_make(); |
| 43 | +#if WITH_TASKS_INFO |
| 44 | + register_tasks(); |
| 45 | +#endif |
35 | 46 | } |
36 | 47 |
|
37 | 48 | /** 'restart' command restarts the program */ |
@@ -72,6 +83,36 @@ static void register_free() |
72 | 83 | ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) ); |
73 | 84 | } |
74 | 85 |
|
| 86 | +/** 'tasks' command prints the list of tasks and related information */ |
| 87 | +#if WITH_TASKS_INFO |
| 88 | + |
| 89 | +static int tasks_info(int argc, char** argv) |
| 90 | +{ |
| 91 | + const size_t bytes_per_task = 40; /* see vTaskList description */ |
| 92 | + char* task_list_buffer = malloc(uxTaskGetNumberOfTasks() * bytes_per_task); |
| 93 | + if (task_list_buffer == NULL) { |
| 94 | + ESP_LOGE(__func__, "failed to allocate buffer for vTaskList output"); |
| 95 | + return 1; |
| 96 | + } |
| 97 | + vTaskList(task_list_buffer); |
| 98 | + fputs(task_list_buffer, stdout); |
| 99 | + free(task_list_buffer); |
| 100 | + return 0; |
| 101 | +} |
| 102 | + |
| 103 | +static void register_tasks() |
| 104 | +{ |
| 105 | + const esp_console_cmd_t cmd = { |
| 106 | + .command = "tasks", |
| 107 | + .help = "Get information about running tasks", |
| 108 | + .hint = NULL, |
| 109 | + .func = &tasks_info, |
| 110 | + }; |
| 111 | + ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) ); |
| 112 | +} |
| 113 | + |
| 114 | +#endif // WITH_TASKS_INFO |
| 115 | + |
75 | 116 | /** 'deep_sleep' command puts the chip into deep sleep mode */ |
76 | 117 |
|
77 | 118 | static struct { |
|
0 commit comments