time命令
2005-06-15 12:58
204 查看
Performance Management Guide
Use of the time command to measure CPU use
Use the time command to understand the performance characteristics of a single program and its synchronous children. It reports the real time, that is the elapsed time from beginning to end of the program. It also reports the amount of CPU time used by the program. The CPU time is divided into user and sys. The user value is the time used by the program itself and any library subroutines it calls. The sys value is the time used by system calls invoked by the program (directly or indirectly).The sum of user + sys is the total direct CPU cost of executing the program. This does not include the CPU costs of parts of the kernel that can be said to run on behalf of the program, but which do not actually run on its thread. For example, the cost of stealing page frames to replace the page frames taken from the free list when the program started is not reported as part of the program's CPU consumption.
On a uniprocessor, the difference between the real time and the total CPU time, that is:real - (user + sys)is the sum of all of the factors that can delay the program, plus the program's own unattributed costs. On an SMP, an approximation would be as follows:real * number_of_processors - (user + sys)In approximately the order of diminishing size, the factors can be:
I/O required to bring in the program's text and data
I/O required to acquire real memory for the program's use
CPU time consumed by other programs
CPU time consumed by the operating system
In the following example, the program used in the preceding section has been compiled with -O3 to make it run more quickly. There is very little difference between the real (wall-clock) time required to run the program and the sum of its user and system CPU times. The program is getting all the time it wants, probably at the expense of other programs in the system.# time looper
real 0m3.58s
user 0m3.16s
sys 0m0.04sIn the next example, we run the program at a less favorable priority by adding 10 to its nice value. It takes almost twice as long to run, but other programs are also getting a chance to do their work:# time nice -n 10 looper
real 0m6.54s
user 0m3.17s
sys 0m0.03sNote that we placed the nice command within the time command, rather than the reverse. If we had entered# nice -n 10 time looperwe would have gotten a different time command (/usr/bin/time) with a lower-precision report, rather than the version of the time command we have been using, which is built into the ksh shell. If the time command comes first, you get the built-in version, unless you specify the fully qualified name of /usr/bin/time. If the time command is invoked from another command, you get /usr/bin/time.
Considerations of the time and timex commands
Take several considerations into account when you use either the time or the timex command:The use of the /usr/bin/time and /usr/bin/timex commands is not recommended. When possible, use the time subcommand of the Korn or C shell.
The timex -s command uses the sar command to acquire additional statistics. Because the sar command is intrusive, the timex -s command is also. Especially for brief runs, the data reported by the timex -s command may not precisely reflect the behavior of a program in an unmonitored system.
Because of the length of the system clock tick (10 milliseconds) and the rules used by the scheduler in attributing CPU time use to threads, the results of the time command are not completely deterministic. Because the time is sampled, there is a certain amount of unavoidable variation between successive runs. This variation is in terms of clock ticks. The shorter the run time of the program, the larger the variation as a percentage of the reported result (see Accessing the Processor Timer).
Use of the time or timex command (whether from /usr/bin or through the built-in shell time function) to measure the user or system time of a sequence of commands connected by pipes, entered on the command line, is not recommended. One potential problem is that syntax oversights can cause the time command to measure only one of the commands, without any indication of a user error. The syntax is technically correct; it just does not produce the answer that the user intended.
Although the time command syntax did not change, its output takes on a new meaning in an SMP environment: On an SMP the real, or elapsed time may be smaller than the user time of a process. The user time is now the sum of all the times spent by the threads or the process on all processors.
If a process has four threads, running it on a uniprocessor (UP) system shows that the real time is greater than the user time:# time 4threadedprog
real 0m11.70s
user 0m11.09s
sys 0m0.08sRunning it on a 4-way SMP system could show that the real time is only about 1/4 of the user time. The following output shows that the multithreaded process distributed its workload on several processors and improved its real execution time. The throughput of the system was therefore increased.# time 4threadedprog
real 0m3.40s
user 0m9.81s
sys 0m0.09s
相关文章推荐
- Linux命令之time
- time命令含义
- linux下find命令-atime,-ctime,-mtime真正含义
- 用bat使用date和time命令
- time命令中的real,user以及sys时间
- C# 数据库sql中用参数的方法来执行UPDATE命令,实现更新dataTime类型
- linux中top命令下显示出的PR\NI\RES\SHR\S\%MEM TIME+都代表什么
- Linux命令详解 — time
- 输出 time 命令的结果到文件中
- time 命令用法,注意在求进程实践的时候,real 时间长是因为i/o时间长
- ping 命令 time出现负数
- Linux time 命令在性能分析中的作用
- linux下find命令-atime,-ctime,-mtime真正含义
- ubuntu-基本命令篇-15-系统管理-time命令中Real,User,Sys概念
- Linux下time命令
- Linux命令详解 — time
- time 命令
- Linux系统使用time计算命令执行的时间
- time命令,计算脚本执行时间
- 扒开系统调用的三层皮(下)/给MenuOS增加time和time-asm命令