您的位置:首页 > 运维架构 > Linux

linux 内核/用户空间获取时间

2016-12-29 08:41 501 查看
1、内核空间

 #include<time.h>

struct timeval stime,etime;

do_gettimeofday(&stime);

 ... ... ... ... ...

lsmfts_set_targe_focal(priv->lsMfts,focalLength); //设置targe focla值 focalvalue[0,100]

do_gettimeofday(&etime);

printk("----do_gettimeofday----of setFoccalLength_od time %d us----\n",(etime.tv_sec - stime.tv_sec)*1000000 + (etime.tv_usec - stime.tv_usec)); //即为时间差

return 0;

2、用户空间

 #include <time.h>

 #include <sys/time.h>

 typedef unsigned long long guint64;

 guint64 system_current_time_millis()

  {

  struct timeval tve;

 gettimeofday(&tve,NULL);

 guint64 sec=tve.tv_sec;

 guint64 microseconds=tve.tv_usec;

 guint64 total=sec*G_GINT64_CONSTANT(1000)+microseconds/G_GINT64_CONSTANT(1000);

 return total;

  }

 guint64 system_current_time_nano()

 {

 struct timeval tve;

 gettimeofday(&tve,NULL);

  guint64 sec=tve.tv_sec;

 guint64 microseconds=tve.tv_usec;

 guint64 total=sec*G_GINT64_CONSTANT(1000*1000*1000)+microseconds*G_GINT64_CONSTANT(1000);

 return total;

 }

 guint64 system_current_time_micro()

 {

 struct timeval tve;

  gettimeofday(&tve,NULL);

 guint64 sec=tve.tv_sec;

 guint64 microseconds=tve.tv_usec;

 guint64 total=sec*G_GINT64_CONSTANT(1000*1000)+microseconds;

 return total;

 }

 guint64 time1= system_current_time_millis();

... ... ... ... ...

guint64 time2= system_current_time_millis();

printf("----system_current_time_micro:%llums-%llums = %llu ms----\n", time2,time1,time2-time1);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: