# FreeRTOS run time stats.

**URL:** <https://forums.freertos.org/t/freertos-run-time-stats/3164>\
**Category:** Kernel\
**Created:** [November 20, 2012, 12:44pm UTC](https://forums.freertos.org/t/freertos-run-time-stats/3164 "2012-11-20T12:44:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 20, 2012, 12:44pm UTC](https://forums.freertos.org/t/freertos-run-time-stats/3164/1 "2012-11-20T12:44:19Z")

</div>

**[hurza89](https://sourceforge.net/u/hurza89/)** wrote on [Tuesday, November 20, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/8a415f93/#5766):

Hi,  
I would like to use vTaskGetRunTimeStats() function. I did 3 steps:  
1. configGENERATE\_RUN\_TIME\_STATS  
2. portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS()  
3. portGET\_RUN\_TIME\_COUNTER\_VALUE()  
Then i wanted to use vTaskGetRunTimeStats() function. But compiler said me:

```
              [cc] Starting link
       [cc] arm-none-eabi-gcc -O0 -nostartfiles -Wl,-Map=SuperSystem.map -mcpu=cortex-m3 -mthumb -LC:\CooCox\CoIDE\workspace\SuperSystem -Wl,--gc-sections -Wl,-TC:\CooCox\CoIDE\workspace\SuperSystem/arm-gcc-link.ld -g -o SuperSystem.elf ..\obj\stm32f10x_tim.o ..\obj\startup_stm32f10x_md_vl.o ..\obj\core_cm3.o ..\obj\system_stm32f10x.o ..\obj\DisplayController.o ..\obj\stm32f10x_gpio.o ..\obj\main.o ..\obj\adsf.o ..\obj\requiredMethodsFromMain.o ..\obj\timers.o ..\obj\stm32f10x_rcc.o ..\obj\MotorsController.o ..\obj\stm32f10x_exti.o ..\obj\tasks.o ..\obj\stm32f10x_adc.o ..\obj\alfanumDisplay.o ..\obj\list.o ..\obj\stm32f10x_flash.o ..\obj\stm32f10x_it.o ..\obj\MeasurementsController.o ..\obj\queue.o ..\obj\port.o ..\obj\SSBootstrapper.o ..\obj\misc.o ..\obj\heap_1.o
       [cc] sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
       [cc] c:/program files (x86)/gnu tools arm embedded/4.6 2012q2/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
       [cc] c:/program files (x86)/gnu tools arm embedded/4.6 2012q2/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libg.a(lib_a-abort.o): In function `abort':
       [cc] abort.c:(.text.abort+0xa): undefined reference to `_exit'
       [cc] c:/program files (x86)/gnu tools arm embedded/4.6 2012q2/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libg.a(lib_a-signalr.o): In function `_kill_r':
       [cc] signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
       [cc] c:/program files (x86)/gnu tools arm embedded/4.6 2012q2/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libg.a(lib_a-signalr.o): In function `_getpid_r':
       [cc] signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'
       [cc] collect2: ld returned 1 exit status

```

What is: \_sbrk&nbsp; ? How to fix it ?  
This problem is only when i add function vTaskGetRunTimeStats(). If i delete it, it’s all right.  
I use CooCox.

Best Regards,  
Horza.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 20, 2012, 12:56pm UTC](https://forums.freertos.org/t/freertos-run-time-stats/3164/2 "2012-11-20T12:56:49Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, November 20, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/8a415f93/#0f89):

It looks like your implementation has used a printf() type function (maybe sprintf()) that has resulted in library functions being linked into your application, and that the library function requires you to define some target specific functions.&nbsp; I would guess, from your output, that CooCox is using GCC with Newlib - Newlib is not ideal for small embedded systems.

You have a few choices:

1) Provide stubs for the functions just to shut the linker up.&nbsp; That is ok if the functions are never actually going to be used.&nbsp; See the file newlib\_stubs.c in one of the FreeRTOS/Demo subdirectories.

2) Provide real implementations for the functions.&nbsp; See the syscalls.c files in a couple of sub-directories off of FreeRTOS/Demo for references.

3) Use a different library.&nbsp; Try adding printf-stdarg.c to your project - you will find lots of copies in sub-directories off of FreeRTOS/Demo.&nbsp; printf-stdarg.c implements a tiny sprintf() function that might prevent the Newlilb files being dragged into your build.&nbsp; Be careful though, as snprintf() is not implemented properly in printf-stdarg.c.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 20, 2012, 4:51pm UTC](https://forums.freertos.org/t/freertos-run-time-stats/3164/3 "2012-11-20T16:51:52Z")

</div>

**[hurza89](https://sourceforge.net/u/hurza89/)** wrote on [Tuesday, November 20, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/8a415f93/#2826):

Aa so _vTaskGetRunTimeStats_ function has sprintf. Can i remove this functions from tasks.c file ?, because i don’t need to print it on display, i want to send report about run time through SPI. I removed it, it’s compiled, but i don’t know if I have proper array with RunTimeStats.  
I have additional question, how does this array looks after vTaskGetRunTimeStats() ? is that in each field is another data ? i mean: array is Task’s name, array is AbsTime and array is %Time ?

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 21, 2012, 9:56am UTC](https://forums.freertos.org/t/freertos-run-time-stats/3164/4 "2012-11-21T09:56:26Z")

</div>

**[hurza89](https://sourceforge.net/u/hurza89/)** wrote on [Wednesday, November 21, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/8a415f93/#d760):

I’ve added printf-stdarg.c and it works. But firstly in array from vTaskGetRunTimeStats() function percentage is ok i think, but in each next iteration i have studpid numbers. For example 2558% or more. Is that possible that my 16bit counter has overflow and then vTaskGetRunTimeStats() counts it wrong ? Or should I reset counter after vTaskGetRunTimeStats() ?

Regards.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 21, 2012, 10:11am UTC](https://forums.freertos.org/t/freertos-run-time-stats/3164/5 "2012-11-21T10:11:55Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, November 21, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/8a415f93/#13c8):

The run time stats counter needs to have a resolution higher than the tick count, preferably at least 10 times higher.&nbsp; Because of this, only 32 bit counters are practical.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 22, 2012, 11:24am UTC](https://forums.freertos.org/t/freertos-run-time-stats/3164/6 "2012-11-22T11:24:34Z")

</div>

**[hurza89](https://sourceforge.net/u/hurza89/)** wrote on [Thursday, November 22, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/8a415f93/#c44b):

It’s runs perfectly. Last problem was too small coutern, now with 32bit it’s OK.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 28, 2012, 10:00am UTC](https://forums.freertos.org/t/freertos-run-time-stats/3164/7 "2012-11-28T10:00:52Z")

</div>

**[hurza89](https://sourceforge.net/u/hurza89/)** wrote on [Wednesday, November 28, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/8a415f93/#dd94):

The last case which makes me trouble is that: What happens if 32bit counter overflow ? FreeRTOS detect it ? Or statistics are count again ?

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 28, 2012, 10:27am UTC](https://forums.freertos.org/t/freertos-run-time-stats/3164/8 "2012-11-28T10:27:20Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Wednesday, November 28, 2012](https://sourceforge.net/p/freertos/discussion/382005/thread/8a415f93/#c338):

Once the 32 bit counter overflows that is it. If you want to keep the run time stats going for ever then you could use a 64 bit counter but that is very inefficient. Or you could change the implementation. Normally the counter is only used for debugging and optimization though so not for more than a few hours at a time maximum.
