Proposal for a Lightweight API to Retrieve Task Runtime Statistics

Currently, the existing method to gather task runtime statistics involves traversing all tasks in the system and outputting the data using a fixed format to pcWriteBuffer. However, this approach relies on snprintf(), which can be too resource-intensive for embedded systems.

I propose introducing a more efficient API that allows users to query the runtime statistics for a specific task using its TaskID. The API would return a dedicated structure, which would be more practical and reduce system overhead.

For example, the proposed function could be:

void vTaskGetStatus(TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, uint32_t *tick, uint32_t *run_time);

Does one of the following APIs solve your usecase:

  1. uxTaskGetSystemState() - FreeRTOS™
  2. vTaskGetInfo() - FreeRTOS™
1 Like

Hi @aggarg

The function uxTaskGetSystemState() - FreeRTOS™ allows users to retrieve runtime information for all tasks. However, users are required to prepare an array to store this information, which can consume significant stack space.

Additionally, if the user is only interested in a few specific tasks rather than all of them, they must manually search for those tasks in the returned array. This process can be inefficient. Therefore, using an API to retrieve the runtime statistics for specific tasks could be a more flexible and efficient solution.
Just my two cends. :slightly_smiling_face:

Which is what vTaskGetInfo is for. It gets the data for one specific task, specified by its handle.

@richard-damon @aggarg
Great!!! vTaskGetInfo() - FreeRTOS™ is what I want.
Thanks.