Linux获取毫秒级时间
Linux获取毫秒级时间
Moakap
在软件设计中经常会用到关于时间的处理,用来计算语句、函数的执行时间,这时就需要精确到毫秒甚至是微妙的时间。
int gettimeofday(struct
timeval *tv, struct timezone *tz);
int settimeofday(const
struct timeval *tv , const struct timezone *tz);
struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /*
microseconds */
};
struct timezone {
int tz_minuteswest; /* minutes
west of Greenwich
*/
int
tz_dsttime; /* type of DST
correction */
};
下面是个简单的例子,用来统计程序的执行时间:
…
struct timeval
t_start,t_end;
long cost_time = 0;
//get start
time
gettimeofday(&t_start,
NULL);
printf("Start
time: %ld us", t_start.tv_usec);
//some
operation
…
//get end time
gettimeofday(&t_end,
NULL);
printf("End
time: %ld us", t_end.tv_usec);
//calculate
time slot
cost_time =
t_end.tv_usec - t_start.tv_usec;
printf("Cost
time: %ld us", cost_time);
…
输出:
Start time:
438061 us
End time:
459867 us
Cost time:
21806 us
相关文档:
lsmod(list modules)
功能说明:显示已载入系统的模块。
语 法:lsmod
补充说明:执行lsmod指令,会列出所有已载入系统的模块。Linux操作系统的核心具有模块化的特性,应此在编译核心时,务须把全部的功能都放入核心。您可以将这些功能编译成一个个单独的模块,待需要时再分别载入。
范例:
[root@lin ......
在LINUX的时钟中断中涉及至二个全局变量一个是xtime,它是timeval数据结构变量,另一个则是jiffies,首先看timeval结构
struct timeval
{
time_t tv_sec; /***second***/
susecond_t tv_usec;/***microsecond***/
}
到底microsecond是毫秒还是微秒??
1秒=1000毫秒(3个零),1秒=1000 000微秒(6个零),1秒=1 ......
Name
hosts - The static table lookup for host names
Synopsis
/etc/hosts
Description
This manual page describes the format of the /etc/hosts
file. This file is a simple text file that
associates IP addresses with hostnames, one line per IP address. For
each host a single line should be presen ......
1,显著影响系统性能的4种资源
(1),CPU时间
(2),内存
(3),硬盘I/O
(4),网络I/O
2,分析CPU使用情况
使用vmstat采集CPU的性能瓶颈
[root@local]# vmstat 2
procs -----------memory---------- ---swap-- -----io-- ......