-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
esp32/modesp32: Implement idf_task_stats(). #12732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,6 +212,49 @@ static mp_obj_t esp32_idf_heap_info(const mp_obj_t cap_in) { | |
} | ||
static MP_DEFINE_CONST_FUN_OBJ_1(esp32_idf_heap_info_obj, esp32_idf_heap_info); | ||
|
||
#if CONFIG_FREERTOS_USE_TRACE_FACILITY | ||
static mp_obj_t esp32_idf_task_info(void) { | ||
const size_t task_count_max = uxTaskGetNumberOfTasks(); | ||
TaskStatus_t *task_array = m_new(TaskStatus_t, task_count_max); | ||
uint32_t total_time; | ||
const size_t task_count = uxTaskGetSystemState(task_array, task_count_max, &total_time); | ||
|
||
mp_obj_list_t *task_list = MP_OBJ_TO_PTR(mp_obj_new_list(task_count, NULL)); | ||
for (size_t i = 0; i < task_count; i++) { | ||
mp_obj_t task_data[] = { | ||
mp_obj_new_int_from_uint((mp_uint_t)task_array[i].xHandle), | ||
mp_obj_new_str(task_array[i].pcTaskName, strlen(task_array[i].pcTaskName)), | ||
MP_OBJ_NEW_SMALL_INT(task_array[i].eCurrentState), | ||
MP_OBJ_NEW_SMALL_INT(task_array[i].uxCurrentPriority), | ||
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS | ||
mp_obj_new_int_from_uint(task_array[i].ulRunTimeCounter), | ||
#else | ||
mp_const_none, | ||
#endif | ||
mp_obj_new_int_from_uint(task_array[i].usStackHighWaterMark), | ||
#if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID | ||
MP_OBJ_NEW_SMALL_INT(task_array[i].xCoreID), | ||
#else | ||
mp_const_none, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Maybe -1 can be used here instead of None, so that it's uniformly an integer? (I did see that FreeRTOS returns -1 for some tasks' xCoreID, such as "Tmr Svc", so maybe a different sentinel integer like 255, or -255?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: Partly because there's already different integer values to interpret I think explicitly using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I think that's fine to keep it as |
||
#endif | ||
}; | ||
task_list->items[i] = mp_obj_new_tuple(7, task_data); | ||
} | ||
|
||
m_del(TaskStatus_t, task_array, task_count_max); | ||
mp_obj_t task_stats[] = { | ||
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS | ||
MP_OBJ_NEW_SMALL_INT(total_time), | ||
#else | ||
mp_const_none, | ||
#endif | ||
task_list | ||
}; | ||
return mp_obj_new_tuple(2, task_stats); | ||
} | ||
static MP_DEFINE_CONST_FUN_OBJ_0(esp32_idf_task_info_obj, esp32_idf_task_info); | ||
#endif | ||
|
||
static const mp_rom_map_elem_t esp32_module_globals_table[] = { | ||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp32) }, | ||
|
||
|
@@ -228,6 +271,9 @@ static const mp_rom_map_elem_t esp32_module_globals_table[] = { | |
{ MP_ROM_QSTR(MP_QSTR_mcu_temperature), MP_ROM_PTR(&esp32_mcu_temperature_obj) }, | ||
#endif | ||
{ MP_ROM_QSTR(MP_QSTR_idf_heap_info), MP_ROM_PTR(&esp32_idf_heap_info_obj) }, | ||
#if CONFIG_FREERTOS_USE_TRACE_FACILITY | ||
{ MP_ROM_QSTR(MP_QSTR_idf_task_info), MP_ROM_PTR(&esp32_idf_task_info_obj) }, | ||
#endif | ||
|
||
{ MP_ROM_QSTR(MP_QSTR_NVS), MP_ROM_PTR(&esp32_nvs_type) }, | ||
{ MP_ROM_QSTR(MP_QSTR_Partition), MP_ROM_PTR(&esp32_partition_type) }, | ||
|
Uh oh!
There was an error while loading. Please reload this page.