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);
#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);
相关文章推荐
- NFS服务配置
- linux 实战篇 攻略(一)
- Linux简单操作命令行之一,普通命令
- linux学习笔记--finger命令
- Linux 操作系统
- Linux下让进程在后台可靠运行的几种方法
- Centos安装php高版本
- 如何调整Linux系统为正确时区
- 总结四条对学习Linux系统有帮助的方法
- Linux常用命令(持续...)
- centos下Glassfish集群搭建
- RocketMQ笔记(1)_Linux下编译部署
- Linux学习笔记--newusers命令
- udev (简体中文)
- 话说linux内核
- CentOS安装ActiveMQ
- centos7下安装Composer
- Linux基本安全处理
- Linux速成教程
- 快速操作Linux终端命令行的快捷键列表