Processor occupancy tracing: why isn't it there?

erupter wrote on Friday, June 13, 2014:

I’m thinking about using the TASK_SWITCHED_IN/OUT macros to record the time spent in processing time by each task.
This is something available on every operating system and I wonder why that isn’t part of the normal tracing capabilities.

Surely there is a reason for not including such a functionality by default?

davedoors wrote on Friday, June 13, 2014:

You just have to fill in the macro that returns the time stamp, which can’t be part of the standard kernel code because where it comes from depends on the mcu you are using and which timers are free on that mcu. There are some standard ways of providing the time stamp on Cortex mcus that use raw systick timer values.

you can also look at and

erupter wrote on Friday, June 13, 2014:

Thanks Dave

I’m again getting up to speed on FreeRTOS after years, and I totally forgot about this -_-
By looking into my old code I had the runtime stats setup already, with the core timer and everything.

I’m getting old :stuck_out_tongue:
I remember reading something about the impact of the tracing features, but can’t find it. Do you know anything about this?

davedoors wrote on Friday, June 13, 2014:

The timing impact? Well, as with all the features that add code (stack overflow detection, assert points, and the like) there is a code size and execution speed impact. The impact of gathering run time information depends on the implementation of the function that returns the time stamp. If it is simply reading a register then the impact will be one read, and one write, per context switch (actually, probably a little more). If the time stamp needs to be pre-processed then the impact will be higher.

Formatting statistical information into human readable table is another matter. That takes a long time and is not really something you want to be doing outside of your debug code.