vTaskGetRunTimeStats increases flash use

michalrz wrote on Saturday, July 14, 2012:


I have an issue with Run Time Stats. Adding vTaskGetRunTimeStats function to my code increases flash use by more than 20kB!
Stats seems to be working fine, but increased flash use doesn’t look like a normal behaviour.
Did someone have a similar problem?

Here is the memory use before and after adding vTaskGetRunTimeStats function

text    data     bss     dec
42124    1444   19148   62716
19648    1320   19096   40064

My code is running on STM32 CM3 and use ARM Sourcery GCC Toolchain


rtel wrote on Saturday, July 14, 2012:

The run time stats code itself is very small, but it makes use of C library functions that are not used anywhere else in the code.  As soon as you include run time stats you will be pulling in a lot of extra library functions that can bloat your code, depending on your GCC supplier.  Companies such as Rowley and Code Red have their own libraries build specifically for embedded systems.  Other suppliers use things like NewLib which is a disaster on a small micro.

There are a couple of things you can do.  First, avoid using the libraries that come with your compiler.  Normally, this can be done by simply including the printf-stdarg.c source file in your project.  Search for it in the FreeRTOS/Demo directory, it is included in a lot of projects.  The file implements, in a basic and very stack friendly way, the functions needed by the run time stack.  If these functions are defined in your project they will not be pulled in from the compilers libraries.

The second thing you can do is ensure the compiler is configured to remove unused code.  Most compilers do that by default, but the GCC default is not to do it so you have to tell it explicitly using the -ffunction-sections and -fdata-sections command line options to the compiler, and the -no-gc-sections linker option.


michalrz wrote on Saturday, July 14, 2012:

I added printf-stdarg.c as you suggested and it helped very well! Now only 600bytes more of flash used.
Thank you a lot for your help.