When reading the implementation of the function ulTaskGetRunTimeCounter, I feel if it is called for the current running task (i.e., with the parameter being NULL), the returned time counter value will not include the time since the task was switched in because the counter pxTCB->ulRunTimeCounter is only updated on context switch.
Is my understanding correct?
Yes, your understanding is absolutely correct.
Thanks, Gaurav. If the task has high priority and has been running for long time, the reported time will have remarkable error.
Yes, you are right. If you have a long running high priority task which hogs the CPU, you may consider adding occasional yields to update the run time counter.