Figuring out how long a task was placed in a block state

unknowcoder wrote on Wednesday, May 16, 2018:


I want to measure how long a task was placed in a block state. Is there any easy way to do this.
I have a very complicated call sequecne and various parts of the sequence could block.
Basically I want to measure how long the task had been placed in the block state for so I can know if the task was ever asleep.

I am considering using vTaskSetTimeOutState() but doing this will effectly measure not only the block time but the processing time for the code execution. But there certain parts of the code that could spin doing some very heavy work.

rtel wrote on Wednesday, May 16, 2018:

Probably the simplest way would be to have the task measure it itself -
it can store the time both before and after calling a blocking function
and then compare the two when it exits the blocking function.

The most accurate method would be to use the trace tool

The trace tool uses the trace macros, which you can also just define
yourself to take any specific measurements you want.

unknowcoder wrote on Thursday, May 17, 2018:

Hi Richard
the trace tool looks very powerful.
For now I went with the simple approach I wrapped all the blocking calls so I can measure the time it blocked.
This seems to be working well.
Thanks for the input.