在LINUX驱动中观察程序执行时间可使用如下的办法
void my_calc_time(int iStart)
{
static volatile unsigned int u32Max = UINT_MAX;
static long iTimebuffer[1000];
static unsigned long long t1,t2;
unsigned long nanosec_rem;
static int iIndex=0;
if (iStart)
{
t1 = cpu_clock(u32Max);
return;
}
else
t2 = cpu_clock(u32Max);
t2 = t2 - t1;
nanosec_rem = do_div(t2, 1000000000);
if (t2) //more than 1 Second
{
iTimebuffer[iIndex] = 999999;
}
else
{
iTimebuffer[iIndex] = nanosec_rem/1000; //micro second
}
iIndex ++;
if (iIndex==1000)
{
for(iIndex = 0;iIndex < 1000;iIndex++)
{
printk(" %04d,%06d\n",iIndex,(u32)iTimebuffer[iIndex]);
}
iIndex =0;
}
}
在程序执行前 my_calc_time(1)
程序执行结束时 my_calc_time(0)
此时比较前后两次的插值即可
cpu_clock返回CPU启动以来到现在的时间值 单位ns
阅读(1515) | 评论(0) | 转发(1) |