# Bug fix  - runtime statistics collection

**URL:** <https://forums.freertos.org/t/bug-fix-runtime-statistics-collection/3491>\
**Category:** Kernel\
**Created:** [August 14, 2013, 7:39am UTC](https://forums.freertos.org/t/bug-fix-runtime-statistics-collection/3491 "2013-08-14T07:39:18Z")\
**Posts on this page:** 3\
**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:** [August 14, 2013, 7:39am UTC](https://forums.freertos.org/t/bug-fix-runtime-statistics-collection/3491/1 "2013-08-14T07:39:18Z")

</div>

**[philpem](https://sourceforge.net/u/philpem/)** wrote on [Wednesday, August 14, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/99aae401/#366c):

Hi,

There appears to be a bug in FreeRTOS 7.5.2’s tasks.c.

If a FreeRTOS application enables runtime statistics and defines the portALT\_GET\_RUN\_TIME\_COUNTER\_VALUE macro but does not provide the portGET\_RUN\_TIME\_COUNTER\_VALUE function, tasks.c will fail to link (or possibly fail to compile at all, depending on compiler warning/error promotion options).

To fix this, replace the following code block in tasks.c:

```
				#if ( configGENERATE_RUN_TIME_STATS == 1)
				{
					if( pulTotalRunTime != NULL )
					{
						*pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();
					}
				}
				#else

```

With this:

```
				#if ( configGENERATE_RUN_TIME_STATS == 1)
				{
					if( pulTotalRunTime != NULL )
					{
					#ifdef portALT_GET_RUN_TIME_COUNTER_VALUE
						portALT_GET_RUN_TIME_COUNTER_VALUE( *pulTotalRunTime );
					#else
						*pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();
					#endif
					}
				}
				#else

```

Thanks,  
Phil.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 14, 2013, 8:11am UTC](https://forums.freertos.org/t/bug-fix-runtime-statistics-collection/3491/2 "2013-08-14T08:11:31Z")

</div>

**[philpem](https://sourceforge.net/u/philpem/)** wrote on [Wednesday, August 14, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/99aae401/#9482):

Just had a dig through SVN. Looks like this was introduced in rev 1960 (FreeRTOS 7.4.2 probably didn’t have this bug, but 7.5.0 certainly did):

[http://freertos.svn.sourceforge.net/viewvc/freertos/trunk/FreeRTOS/Source/tasks.c?r1=1959&r2=1960&](http://freertos.svn.sourceforge.net/viewvc/freertos/trunk/FreeRTOS/Source/tasks.c?r1=1959&r2=1960&)

The proverbial “smoking gun” is at Line 1489. Note that rev 1959 contains an ifdef to check whether the portALT\_GET\_RUN\_TIME\_COUNTER\_VALUE macro is declared and uses the aforementioned macro if it is. Failing that, it falls back to using portGET\_RUN\_TIME\_COUNTER\_VALUE. The replacement code on the right (line 1491 onwards) does not contain this ifdef and thus introduces a bug.

---

<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:** [August 14, 2013, 8:43am UTC](https://forums.freertos.org/t/bug-fix-runtime-statistics-collection/3491/3 "2013-08-14T08:43:12Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, August 14, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/99aae401/#e5fd):

Thank you for taking the time to report this.

I have committed the fix to SVN and added a note with a link to the fix in the “known issues” list.

Regards.
