time命令

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.04s

In 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.03s

Note that we placed the nice command within the time command, rather than the reverse. If we had entered

# nice -n 10 time looper

we 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.08s

    Running 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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
sa 命令 sa1 命令 sa2 命令 sact 命令 sadc 命令 sar 命令 savebase 命令 savecore 命令 savevg 命令 scan 命令 sccs 命令 sccsdiff 命令 sccshelp 命令 schedo 命令 schedtune 命令 scls 命令 script 命令 sdiff 命令 secldapclntd 守护进程 sectoldif 命令 securetcpip 命令 sed 命令 send 命令 sendbug 命令 sendmail 命令 setclock 命令 setgroups 命令 setmaps 命令 setsenv 命令 settime 命令 setuname 命令 sh 命令 shconf 命令 shell 命令 show 命令 showmount 命令 shutacct 命令 shutdown 命令 size 命令 skulker 命令 slattach 命令 sleep 命令 slibclean 命令 sliplogin 命令 slocal 命令 smcaprop 命令 smdefca 命令 smdemon.cleanu 命令 smexpcacert 命令 smgenkeycr 命令 smgenprivkr 命令 smimpcacert 命令 smimpservercert 命令 sminstkey 命令 smit 命令 smitty 命令 smlistcerts 命令 smserverprop 命令 smsigncert 命令 smundefca 命令 snap 命令 snapcore 命令 snapshot 命令 snmpevent 命令 snmpd 守护进程 snmpdv1 守护进程 snmpdv3 守护进程 snmpinfo 命令 snmpmibd 守护进程 snmptrap 命令 snmpv3_ssw 命令 sno 命令 soelim 命令 sort 命令 sortbib 命令 sortm 命令 spell 命令 spellin 命令 spellout 命令 split 命令 splat 命令 splitvg 命令 splitlvcopy 命令 splp 命令 spost 命令 spray 命令 sprayd 守护进程 srcmstr 守护进程 startcondresp 命令 start-secldapclntd 命令 stop-secldapclntd 命令 startrpdomain 命令 startrpnode 命令 startsrc 命令 startup 命令 startvsd 命令 startx 命令 statd 守护进程 statvsd 命令 stopcondresp 命令 stoprpdomain 命令 stoprpnode 命令 stopsrc 命令 stopvsd 命令 stpinet 方法 strace 命令 strchg 命令 strclean 命令 strconf 命令 strerr 守护进程 strinfo 命令 strings 命令 strip 命令 stripnm 命令 strload 命令 strreset 命令 struct 命令 sttinet 方法 stty 命令 stty-cxma 命令 style 命令 su 命令 subj 命令 sum 命令 survd 守护进程 suspendvsd 命令 svmon 命令 swap 命令 swapoff 命令 swapon 命令 swcons 命令 sync 命令 synclvodm 命令 syncvg 命令 syscall 命令 sysck 命令 syscorepath 命令 sysdumpdev 命令 sysdumpstart 命令 sysline 命令 syslogd 守护进程 tab 命令 tabs 命令 tail 命令 talk 命令 talkd 守护进程 tapechk 命令 tar 命令 tbl 命令 tc 命令 tcbck 命令 tcopy 命令 tcpdump 命令 tctl 命令 tee 命令 telinit 或 init 命令 telnet、tn 或 tn3270 命令 telnetd 守护进程 termdef 命令 test 命令 tftp 或 utftp 命令 tftpd 守护进程 tic 命令 time 命令 timed 守护进程 timedc 命令 timex 命令 tip 命令 tokstat 命令 topas 命令 topsvcs 命令 topsvcsctrl 命令 touch 命令 tprof 命令 tput 命令 tr 命令 trace 守护进程 traceroute 命令 tracesoff 命令 traceson 命令 trbsd 命令 trcdead 命令 trcevgrp 命令 trcnm 命令 trcrpt 命令 trcstop 命令 trcupdate 命令 troff 命令 trpt 命令 true 或 false 命令 truss 命令 tset 命令 tsh 命令 tsm 命令 tsort 命令 ttt 命令 tty 命令 tunchange 命令 tuncheck 命令 tundefault 命令 tunrestore 命令 tunsave 命令 turnacct 命令 turnoff 命令 turnon 命令 tvi 命令 twconvdict 命令 twconvfont 命令 type 命令 ucfgif 方法 ucfginet 方法 ucfgqos 方法 ucfgvsd 命令 uconvdef 命令 udefif 方法 udefinet 方法 udfcheck 命令 udfcreate 命令 udflabel 命令 uil 命令 uimx 命令 ul 命令 ulimit 命令 umask 命令 umount 或 unmount 命令 umountall 命令 unalias 命令 uname 命令 uncompress 命令 undefvsd 命令 unexpand 命令 unfencevsd 命令 unget 命令(SCCS) unifdef 命令 uninstallms 命令 uniq 命令 units 命令 unlink 命令 unloadipsec 命令 unmirrorvg 命令 unpack 命令 untab 命令 update 命令 updatevsdnode 命令 updatevsdtab 命令 updatevsdvg 命令 uprintfd 守护进程 uptime 命令 users 命令 usrck 命令 utmpd 守护进程 uucheck 命令 uucico 守护进程 uuclean 命令 uucleanup 命令 uucp 命令 uucpadm 命令 uucpd 守护进程 uudecode 命令 uudemon.admin 命令 uudemon.cleanu 命令 uudemon.hour 命令 uudemon.poll 命令 uuencode 命令 uuid_gen 命令(NCS) uukick 命令 uulog 命令 uuname 命令 uupick 命令 uupoll 命令 uuq 命令 uusched 守护进程 uusend 命令 uusnap 命令 uustat 命令 uuto 命令 uutry 命令 Uutry 命令 uux 命令 uuxqt 守护进程
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值