Vxworks中clock_gettime()的使用,不知道为什么结果是0!!

xiuzhenkuangren 2012-07-02 11:33:08
想测一下程序运行的时间,时间估计在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;
}

...全文
1184 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cz_三无产品 2013-06-05
  • 打赏
  • 举报
回复
我前段时间刚研究过这个问题。 这个首先要看的tcik 配置是多少。支持纳秒级的不? 你可以先看下秒级的在不在走。 看你的代码,秒级的至少应该要走2S。 当VXWORKS 系统起来后,系统时钟就在运行了,是从1970年1月1日开始计时,除非运行的时候发现错误,他会清0.或者你可以先调用下clock_Settime 设置一个时间到系统中去。
hqftom888168 2013-05-13
  • 打赏
  • 举报
回复
是不是系统时间没有初始化啊,先手动调用看看。
szk6432 2013-04-30
  • 打赏
  • 举报
回复
我也遇到了同样的问题,同问
Nicole3008 2012-07-15
  • 打赏
  • 举报
回复
用ticks()试试
YTerrenceLau 2012-07-04
  • 打赏
  • 举报
回复
是不是要加组件啊。

2,180

社区成员

发帖
与我相关
我的任务
社区描述
xworks是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统。
社区管理员
  • VxWorks开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧