Search code examples
taskvxworksexecution-time

computing execution time of tasks in VxWorks


I want to calculate the execution time of a series of tasks, I initiate a task and then activate it, I use taskCreateHookAdd to start the timer and on every switch on each task I will recalculate the time using taskSwitchHookAdd. After the tasks are deleted. I calculate the time one last time in taskDeleteHookAdd.

I created 4 tasks in my system, they are Insert, Traverse,Delete,Search for Binary trees.at the end the task execution time I calculate doesn't seem ok for two of my tasks, some times they are 0. and the rest of the time the have the exact same value. I have checked the priorities of the tasks but they seem to be ok. all the tasks have implementation and they are not empty. you can see switch part of my code below, I'm sure the other parts work fine (by debugging), but I'm not so sure about the switch hook. I would appreciate it if you could help me with this.thanks in advance.

` void switchtaskHook(WIND_TCB *pOldTcb, WIND_TCB *pNewTcb ) {

if((int)pOldTcb == tidInsert)
{
    inserttotal+=tickGet()-inserttick;

}
else if((int)pOldTcb == tidTraverse)
{
    traversetotal+=tickGet()-traversetick;

}
else if((int)pOldTcb == tidSearch)
{
    searchtotal+=tickGet()-searchtick;//;count++;

}
else if((int)pOldTcb == tidDelete)
{
    deletetotal+=tickGet()-deletetick;

}

if((int)pNewTcb == tidInsert)
{
    inserttick=tickGet();

else if((int)pNewTcb == tidTraverse)
    {
        traversetick=tickGet();

    }
else if((int)pNewTcb == tidSearch)
    {
        searchtick=tickGet();

    }
else if((int)pNewTcb == tidDelete)
    {
        deletetick=tickGet();   
    }

}

`


Solution

  • please read the manual entry for tickGet().

    It returns the system tick count which typically runs at 60 to 2KHz. Much too coarse to do performance measurements. This is controlled by the BSP and you really don't want to change it without good reasons (and the upper rate is typically 8KHz, which is still too coarse) since it can impact the system overhead.

    A better approach is to use the timestamp driver which typically has microsecond resolution. Look for sysTimestamp* function in the documentation.