Reset tasks statistics

I prepare function for displaying tasks statistic using uxTaskGetSystemState().
I would like to write another function for resetting time statistics. I am able to reset pulTotalRunTime which is one of my free running counters (RTI). But what about resetting ulRunTimeCounter for each task? There is an issue with access to pxReadyTasksLists because it is a static array stored in os_task.c
Is it possible to reset all ulRunTimeCounters?

There is no easy way of doing this currently because it means accessing each task’s TCB. There are methods of doing that, as demonstrated by uxTaskGetSystemState() - but it’s an expensive operation. This is a frequent ask though, so I think we should make it easier.

You can also use macros such as traceTASK_SWITCHED_IN to implement your own method of collecting statistics.

I have implemented something that does this via the configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H #define in FreeRTOSConfig.h and a freertos_tasks_c_additions.h file with code to do this.

The code is based on the uxTaskGetSystemState function to access all the tasks, but as Richard Barry says, this is a somewhat expensive operation, and you really need it in a form of. a ‘critical section’ to get you into the right state. (I suspend the scheduler, as that is enough).

1 Like

Thanks for tip.
I saw your implementation somewhere in the network but I it looks like a have no option to use that. I am using FreeRTOS V9.0.0 and it looks like there is no define such configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H (and freertos_tasks_c_additions.h).
I suppose my version has no ability to add additions in this way.

Thanks for reply.
As I said I am using uxTaskGetSystemState() to display statistics. In this function copy of TCBs is being made and it is available in pxTaskStatusArray which is an argument of this function.
I have asked about how to reset statistics of all tasks.

@richard-damon gives the tip. But in my port of FreeRTOS (based on FreeRTOS V9.0.0) I don’t have macro configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H. For now, I have no see any possibility to reset static variables which are a part of tasks.c without modifying FreeRTOS source code which from my point of view is unacceptable.

This is the code you could add to the bottom of your V9 kernel: FreeRTOS-Kernel/tasks.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub

Alternatively, if you don’t want to edit the code, use the tasks_test_access_functions.h header file instead to do exactly the same thing in V9: FreeRTOS/tasks.c at V9.0.0 · FreeRTOS/FreeRTOS · GitHub

1 Like