# Make runtime stats working with compiler optimization enabled

**URL:** <https://forums.freertos.org/t/make-runtime-stats-working-with-compiler-optimization-enabled/9846>\
**Category:** Kernel\
**Created:** [May 22, 2020, 4:08pm UTC](https://forums.freertos.org/t/make-runtime-stats-working-with-compiler-optimization-enabled/9846 "2020-05-22T16:08:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![the78mole](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/the78mole/32/455_2.png) [@the78mole](https://forums.freertos.org/u/the78mole)\
**Post date:** [May 22, 2020, 4:08pm UTC](https://forums.freertos.org/t/make-runtime-stats-working-with-compiler-optimization-enabled/9846/1 "2020-05-22T16:08:21Z")

</div>

Hi forums,

I’m currently on profiling a FreeRTOS application and it’s my first time to use the run-time statistics feature of FreeRTOS together with the Eclipse “FreeRTOS Task List” view.

When switching on compiler optimization (above -O0), the runtime stats vanish. A workaround is described at the end of this blog post on Atollic and FreeRTOS:

> **[Visualizing run-time statistics using FreeRTOS and Atollic TrueSTUDIO Pro](http://blog.atollic.com/visualizing-run-time-statistics-using-freertos)**
>
> How to setup run-time statistics for FreeRTOS in Atollic TrueSTUDIO kernel aware debugger.

To solve the issue sustainably, I would recommend to declare `ulTotalRunTime = 0UL` in tasks.c as volatile.

> <https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/10bbbcf0b9bcab1869b3bac3987d32116f351718/tasks.c#L396>

The second suggestion of the blog post, to disable optimization for tasks.c completely, affects performance too much.

Is it worth to raise an issue for that on GitHub?

Regards,  
Daniel

---

<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:** [May 22, 2020, 4:23pm UTC](https://forums.freertos.org/t/make-runtime-stats-working-with-compiler-optimization-enabled/9846/2 "2020-05-22T16:23:29Z")

</div>

Please just create a pull request on Github with the volatile added - thanks.

---

<div class="post-metadata">

**Author:** ![the78mole](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/the78mole/32/455_2.png) [@the78mole](https://forums.freertos.org/u/the78mole)\
**Post date:** [May 22, 2020, 5:20pm UTC](https://forums.freertos.org/t/make-runtime-stats-working-with-compiler-optimization-enabled/9846/3 "2020-05-22T17:20:50Z")

</div>

Done:

> <https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/62>
