Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

How to print vTaskGetRunTimeStats report?

Posted by Diptopal Basu on August 21, 2013
I wanted to print out the run time statistics value for my LPC1768 in the same format as it appears in the webserver example, but instead of using the webserver, I wanted to print it out to the console. Is there any example in which vTaskGetRunTimeStats is called and the returned stats is stored in some buffer from which I could print out the values? I am unable to understand where vTaskGetRunTimeStats is returning the statistics and from where I can display them. I have the drivers to print strings out to Teraterm or any terminal program, so printing out strings is not a problem with me. I am referring http://www.freertos.org/rtos-run-time-stats.html and http://www.freertos.org/a00021.html#vTaskGetRunTimeStats. Thanks in advance.

RE: How to print vTaskGetRunTimeStats report?

Posted by Diptopal Basu on August 21, 2013
I think I got it, after checking the function call, I think assigning a char* somevariable and passing that to vTaskGetRunTimeStats would populate somevariable which I can print out. Hope this is correct.

RE: How to print vTaskGetRunTimeStats report?

Posted by Diptopal Basu on August 21, 2013
I am not able to locate the Timer0 handler for vTaskGetRunTimeStats . If Timer0 is configured, I am assuming that there will be a handler also somewhere?

RE: How to print vTaskGetRunTimeStats report?

Posted by Richard on August 21, 2013
There are lots of ways of generating the time base for the run time stats. Some of the demos use generic code that obtains the time base from the SysTick timer. The first page you link to provides source code that configures a peripheral timer to do it.

“I am not able to locate the Timer0 handler for vTaskGetRunTimeStats . If Timer0 is configured, I am assuming that there will be a handler also somewhere?”


Where are you looking? I'm not sure if you are saying that you have configured Timer0 in your project, and are not trying to find where it is handled (in which case you will have to write the handler yourself), or that you are looking at the demo referenced from the page you link to (in which case there is no interrupt and you just read the timers count value directly using #define portGET_RUN_TIME_COUNTER_VALUE() TIM0->TC).

See also http://www.freertos.org/uxTaskGetSystemState.html

Regards.

RE: How to print vTaskGetRunTimeStats report?

Posted by Diptopal Basu on August 22, 2013
Yes I am referring to the demo referenced in the page I linked. Here is my setting in FreeRTOSConfig.h relevant to this
#define configGENERATE_RUN_TIME_STATS1
.
.
.
extern void vConfigureTimerForRunTimeStats( void );
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() LPC_TIM0->TC


In the main program, this is the function to set up Timer0, same as the port I am using as reference, GCC RedSuite for LPC1768.

void vConfigureTimerForRunTimeStats( void )
{
const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE = 0x01;

/* This function configures a timer that is used as the time base when
collecting run time statistical information - basically the percentage
of CPU time that each task is utilising. It is called automatically when
the scheduler is started (assuming configGENERATE_RUN_TIME_STATS is set
to 1). */
LPC_printf("Configure Timer called\r\n");
/* Power up and feed the timer. */
LPC_SC->PCONP |= 0x02UL;
LPC_SC->PCLKSEL0 = (LPC_SC->PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);

/* Reset Timer 0 */
LPC_TIM0->TCR = TCR_COUNT_RESET;

/* Just count up. */
LPC_TIM0->CTCR = CTCR_CTM_TIMER;

/* Prescale to a frequency that is good enough to get a decent resolution,
but not too fast so as to overflow all the time. */
LPC_TIM0->PR = ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;

/* Start the counter. */
LPC_TIM0->TCR = TCR_COUNT_ENABLE;
}


I have declared the buffer like this in the main program,

char *stats ;

Now when I am calling the vTaskGetRunTimeStats from one of the tasks I have created, the execution hangs i.e. the printing stops in the console. Normally in the console, the way I have written the code, it prints out all the tasks. I am calling vTaskGetRunTimeStats like this

void vErrorChecks7( void * pvParameters )
{
int i ;
for (;;) {

if( xSemaphoreTake( xSemaphore, ( portTickType ) 100 ) == pdTRUE ) {
LPC_printf(" Task 8 running now and the task stats is \n\r " );
vTaskGetRunTimeStats(stats);
//LPC_printf("%s", stats);
}
else {
LPC_printf("Task 8 Could not get semaphore\n\r");
}
xSemaphoreGive( xSemaphore );

vTaskDelay(8000) ;

}
}


What am I doing wrong ?

I will also look at the link provided for uxTaskGetSystemState().

RE: How to print vTaskGetRunTimeStats report?

Posted by Richard on August 22, 2013
You need to allocate a buffer into which the stats information can be written, and pass a pointer to that buffer into the vTaskGetRunTimeStats() function.

At the moment you are declaring a pointer, but the pointer is not initialised, so you don't know where it is pointing. The vTaskGetRunTimeStats() function is therefore going to write the table of stats information into a random place in your RAM.

This can be easily fixed by changing the line

char *stats;


To

char stats[ 2048];


Assuming 2048 bytes is adequate to hold the generated table of information. Then when you pass stats into the function you are passing a pointer to a 2K buffer. [there are lots of examples of this in the download]

Regards.

RE: How to print vTaskGetRunTimeStats report?

Posted by Diptopal Basu on August 23, 2013
Hi Richard,

Thank you, I made the necessary changes. And I am calling it from one task , it passes first time and hangs the second time at the function call, I'm pasting the relevant code here

signed char stats[1024] ;
.
.
.

void vErrorChecks7( void * pvParameters )
{
for (;;) {

if( xSemaphoreTake( xSemaphore, ( portTickType ) 100 ) == pdTRUE ) {
LPC_printf(" Task 8 running now and the task stats is\n\r " );
vTaskGetRunTimeStats(stats);
LPC_printf("Crossed to here\n\r");
LPC_printf("%s",stats);
}
else {
LPC_printf("Task 8 Could not get semaphore\n\r");
}
xSemaphoreGive( xSemaphore );



vTaskDelay(1000) ;




}
}

RE: How to print vTaskGetRunTimeStats report?

Posted by Dave on August 23, 2013
Please provide more information, like where does it hang and what is it doing when it has hung up.

Does it still hang if you remove the calls to printf?

Do you have stack overflow checking on?

Are any other tasks using printf?

RE: How to print vTaskGetRunTimeStats report?

Posted by Diptopal Basu on August 23, 2013
Hi Dave,

1. If you see the code fragment above, I am just printing out some strings before and after the vTaskGetRunTimeStats call. So once it prints Task 8 running now and the task stats is then it comes to Crossed to here. It tries to print the char string, it prints some garbage, I feel because my printf is faulty. Then it again goes back to print Task 8 running now and the task stats is and then nothing happens. Nothing is printed out.

2. If I remove the printf calls I have no way of knowing if it has hung, but I have commented out the Crossed to here and the printing of the values also, I get the same result as step 1, in that case the Crossed to here and the garbage print of the stats does not come.

3. Stack overflow checking is not on #define configCHECK_FOR_STACK_OVERFLOW0

4. The main uses printf, and this task only, there were other tasks using it but I commented those tasks out. I have even tried it without the mutex but got the same result.

RE: How to print vTaskGetRunTimeStats report?

Posted by Diptopal Basu on August 23, 2013
Hi Dave,

Also if I comment out the vTaskGetRunTimeStats call, the tasks keeps printing Task 8 running now and the task stats is as expected.

RE: How to print vTaskGetRunTimeStats report?

Posted by Richard on August 23, 2013
So you know roughly how far the code gets, but to debug this efficiently you need much more detail. As it is, we don't even know which task is running when it stops so don't know what to suggest for you to try.

I recommend getting yourself a debugger. You will probably sort this out very quickly, or at least be able to provide the information we need to be able to help you through it.

At the moment I would guess that the printf()s are the source of your problem, especially as you note it is already printing garbled strings before the system stops.

Regards.

RE: How to print vTaskGetRunTimeStats report?

Posted by Diptopal Basu on August 23, 2013
Hi Richard,
I will definitely dig deeper and try to provide you more relevant information. Appreciate the prompt support from the Forum.

RE: How to print vTaskGetRunTimeStats report?

Posted by Erich Styger on August 23, 2013
In case this is helpful to this discussion:
I'm using vTaskGetRunTimeStats() in my command line/shell implementation for FreeRTOS to output the state of the tasks:
http://mcuoneclipse.com/2012/08/05/a-shell-for-the-freedom-kl25z-board/

The code for the that particular part can be found here:
https://github.com/ErichStyger/mcuoneclipse/blob/master/Drivers/sw/FreeRTOS.drv
search for this: %'ModuleName'%.vTaskGetRunTimeStats(taskListBufferP, bufSize);

I hope this helps,
Erich

RE: How to print vTaskGetRunTimeStats report?

Posted by Diptopal Basu on August 27, 2013
Thank you, as Richard pointed out, I updated the printf library and all seems to be working fine and I am getting the run time statistics printed out properly.


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists