UInt16T OsTaskGetMaxExecTime( OsHndlT task );
Function OsTaskGetMaxExecTime() may be called by the client application to get the maximum execution time of a task. The argument must be the task handle, returned by OsNewTask(). The function returns the maximum time, in microseconds, that the task has kept control of the CPU since the task was created or this function was last called. Note that calling this function restarts the process of finding the maximum time. A future call to the function may return a shorter time.
If the function argument is zero, the function returns the maximum time for which the scheduler kept control of the CPU in between one task returning control and the next task being started. If the argument is a valid task handle, i.e. less than the number of ECROS tasks allocated at compile time, but the task has not been created, the function will quite reasonably return zero. The handle to the idle task may be passed to the function.
A limitation of the task profiler is that it may not operate correctly if tasks run for more than 25 ms.
The example below shows a function that gets profiler information for a specified task and sends it to the UART0 stream for display on a connected terminal. The maximum execution time is displayed in microseconds. Evaluation of the maximum execution time is restarted by the call to function OsTaskGetMaxExecTime().
static void reportTaskInfo( OsHndlT task )
{
static rom char format[] = "task %u: %u.%.2u%% (%uus)\n";
register UInt16T max;
register UInt16T pct;
max = OsTaskGetMaxExecTime( task );
pct = OsTaskGetPercentUtil( task );
OsFPrintfLite( OS_UART0, format, task, pct & 0xFF, pct >> 8, max );
}