Enhance vTaskList() and vTaskGetRunTimeStats

preetpal wrote on Friday, June 01, 2012:


The vTaskList() and vTaskGetRunTimeStats() can be enhanced to not use pcStatsString at all, which will reduce RAM footprint by 100 bytes.  The execution speed will also benefit.
Instead of sprintf() and strcat(), we can use this:
sprintf(vBuff + strlen(vBuff), “%s …”, taskName);

This way, sprintf will append to vBuff rather than using sprintf and strcat(). 

I’ve also enhanced the vTaskGetRunTimeStats() by adding vTaskResetRunTimeStats().  Without resetting the run time counters, it is difficult to see CPU utilization of recent activity.  This change is really trivial, which is to reset Task counters, ulRunTimeCounter, and have a Portable function to reset the hardware timer.

Let me know if you’d like me to post code.  I’ve got a working/tested version that also follows your coding standards.


rtel wrote on Saturday, June 02, 2012:

Yes!  Please post the code.  The best place would be the “any other” forum in the FreeRTOS Interactive site:


It would also be an idea to post a feature request in the SourceForge tracker to point to your FreeRTOS interactive post too, to ensure it doesn’t get lost in the noise.


hackrid wrote on Wednesday, June 26, 2013:


i did some modifications, too:

static void prvListTaskWithinSingleList( const signed char *pcWriteBuffer, xList *pxList, signed char cStatus )
volatile tskTCB *pxNextTCB, *pxFirstTCB;
unsigned short usStackRemaining;

/* Write the details of all the TCB’s in pxList into the buffer. */
listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );
listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );
#if ( portSTACK_GROWTH > 0 )
usStackRemaining = usTaskCheckFreeStackSpace( ( unsigned char * ) pxNextTCB->pxEndOfStack );
usStackRemaining = usTaskCheckFreeStackSpace( ( unsigned char * ) pxNextTCB->pxStack );

sprintf( pcStatusString, ( char * ) “%**24**s\t\t%c\t%u\t%u\t%u\r\n”, pxNextTCB->pcTaskName, cStatus, ( unsigned int ) pxNextTCB->uxPriority, usStackRemaining, ( unsigned int ) pxNextTCB->uxTCBNumber );
strcat( ( char * ) pcWriteBuffer, ( char * ) pcStatusString );

} while( pxNextTCB != pxFirstTCB );

otherwise the prints in the console windows get messed up by variing task name lengths.

is there a way to sort the output of vTaskList eg by task number so that repetive prints only vary in the numbers printed and not in the task position in the printed table?

hackrid wrote on Wednesday, June 26, 2013:

by the way:

where is the code uploaded by preetpal? did it made it to a freertos release?


rtel wrote on Wednesday, June 26, 2013:

I have already made updates to remove pcStatsString.

The next release will generate the run time and task stats as binary data, then have the existing functions that format the data into a human readable form from the binary data as external utility functions - thus removing sprintf() from tasks.c.  Users are then free to use their own functions to format the data in any way they wish from the binary data, or indeed just use the binary data itself.