Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Enhance vTaskList() and vTaskGetRunTimeStats

Posted by Preet Kang on June 1, 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.


RE: Enhance vTaskList() and vTaskGetRunTimeStats

Posted by Richard on June 2, 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.


RE: Enhance vTaskList() and vTaskGetRunTimeStats

Posted by hackridsourceforge on 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 * ) "%24s\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?

RE: Enhance vTaskList() and vTaskGetRunTimeStats

Posted by hackridsourceforge on June 26, 2013
by the way:

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


RE: Enhance vTaskList() and vTaskGetRunTimeStats

Posted by Richard on 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.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner