Vxworks中clock_gettime()的使用,不知道为什么结果是0!!
想测一下程序运行的时间,时间估计在2分钟以上,想用clock_gettime()函数测,下面是测试clock_gettime()函数的小例子,发现
tp1.tv_nsec;tp2.tv_nsec结果都是0;不知道为什么,跪请高手解答!!
#include "vxWorks.h"
#include "stdioLib.h"
#include "stdio.h"
#include "sysLib.h"
#include "string.h"
#include "taskLib.h"
#include "timers.h"
#include "errnoLib.h"
#include "time.h"
STATUS main(){
struct timespec tp1,tp2;
int i;
if(0!=clock_gettime(CLOCK_REALTIME,&tp1))
{
printf("tp1 error");
printErrno();
}
taskDelay(sysClkRateGet()*2);
if(0!=clock_gettime(CLOCK_REALTIME,&tp2))
{
printf("tp2 error");
printErrno();
}
printf("the first time is %ld\n",tp1.tv_nsec);
printf("the second time is %ld\n",tp2.tv_nsec);
printf("the used time is %ld\n",tp2.tv_nsec-tp1.tv_nsec);
return TRUE;
}