# How to reset vTaskGetRunTimeStats?

**URL:** <https://forums.freertos.org/t/how-to-reset-vtaskgetruntimestats/7861>\
**Category:** Kernel\
**Created:** [May 20, 2019, 3:11pm UTC](https://forums.freertos.org/t/how-to-reset-vtaskgetruntimestats/7861 "2019-05-20T15:11:44Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 20, 2019, 4:49pm UTC](https://forums.freertos.org/t/how-to-reset-vtaskgetruntimestats/7861/3 "2019-05-20T16:49:36Z")

</div>

**[richarddamon](https://sourceforge.net/u/richarddamon/)** wrote on [Monday, May 20, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/425f1134aa/#e787):

I work a freertos\_tacks\_c\_additions.h header file that does that shown below:

Call vTaskClearUsage() to reset all the execution time stats.

Hasn’t been thoughouly tested, but seems to work for me.  
(FreeRTOSAdditions.h is a header file to provide the prototype for vTaskClearUsage() so other files can call this.)

```auto

#ifndef FREERTOS_FREERTOSPP_FREERTOS_TASKS_C_ADDITIONS_H
#define FREERTOS_FREERTOSPP_FREERTOS_TASKS_C_ADDITIONS_H

#include <FreeRTOSAdditions.h>

void vTaskClearUsageSingleList(List_t *pxList)
{
	configLIST_VOLATILE TCB_t *pxNextTCB, *pxFirstTCB;

	if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 ) {
		listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );

		/* Clear Usage for each task that is referenced from
		pxList. See the definition of TaskStatus_t in task.h for the
		meaning of each TaskStatus_t structure member. */
		do {
			listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );
			pxNextTCB->ulRunTimeCounter = 0;
		} while( pxNextTCB != pxFirstTCB );
	}
}

void vTaskClearUsage() {
	UBaseType_t uxQueue = configMAX_PRIORITIES;
	vTaskSuspendAll();
	/* Clear runtime counter for each task in the Ready State */
	do {
		uxQueue--;
		vTaskClearUsageSingleList(&( pxReadyTasksLists[uxQueue] ));
	} while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */

	/* Clear runtime counter for each task in the Blocked state. */
	vTaskClearUsageSingleList(( List_t * ) pxDelayedTaskList);
	vTaskClearUsageSingleList(( List_t * ) pxOverflowDelayedTaskList);

#if( INCLUDE_vTaskDelete == 1 )
	/* Clear runtime counter for each task that has been deleted but not yet cleaned up. */
	vTaskClearUsageSingleList(&xTasksWaitingTermination);
#endif

#if ( INCLUDE_vTaskSuspend == 1 )
	/* Clear runtime counter for each task in the Suspended state. */
	vTaskClearUsageSingleList(&xSuspendedTaskList);
#endif
	ulTaskSwitchedInTime = 0;
	ulTotalRunTime = 0;
	vConfigureTimerForRunTimeStats();
	xTaskResumeAll();
}

#endif /* FREERTOS_FREERTOSPP_FREERTOS_TASKS_C_ADDITIONS_H_ */

```

---

_[View the full topic](https://forums.freertos.org/t/how-to-reset-vtaskgetruntimestats/7861)._
