Linux time command
Uses Linux time command, that particular instruction information measured the elapsed time and system resources required for execution.
Such as CPU time, memory, input and output, and so on. Special attention is needed, some information is displayed on Linux does not come out. This is because the distribution function with time preset mode instruction part of the resources are not the same on Linux, which can not obtain such information in time directive.
grammar
time [options] COMMAND [arguments]
Parameters:
- -o or --output = FILE: setting result output file. This option will output the time to write the specified file. If the file already exists, the system will overwrite its contents.
- -a or --append: use with -o, will write the results to the end of the file, without overwriting the original content.
- -f FORMAT or --format = FORMAT: FORMAT string to set the display mode. When this option is not set, the system will use the default format. But you can use environment variables to set the time format, this way you do not have to sign in each time the system should be set once.
Resource time command can display four areas, namely:
- Time resources
- Memory resources
- IO resources
- Command info
Detailed as follows:
1, Time Resources
E time it takes to execute instructions, the format is: [hour]: minute: second. Note that this figure does not represent the actual CPU time.
E instruction execution time spent, in seconds. Note that this figure does not represent the actual CPU time.
When S instruction execution time in kernel mode (kernel mode) takes in seconds.
When U instruction execution time in user mode (user mode) takes in seconds.
When P ratio occupied CPU instruction execution. In fact, this figure is combined with the user mode kernel mode CPU time divided by the total time.
2, Memory Resources
The maximum physical memory when M execution occupied. The unit is KB
When the average value of physical memory occupied by t execution unit is KB
The total amount of memory occupied by K program execution (stack + data + text) of average size, the unit is KB
D execution of its own data area (unshared data area) of average size, the unit is KB
p own execution stack (unshared stack) of average size, the unit is KB
Sharing content between X program execution (shared text) the average value, the unit is KB
Z system memory page size, the unit is a byte. On the same system, this is a constant
3, IO Resources
The main memory page F of this program the number of errors occur. The so-called main memory page fault refers to a memory page has been replaced with the swap file (swap file) in, and have been assigned to other programs. In this case the content of the page must be read from the swap file inside.
Secondary Memory Page R this program the number of errors occur. The so-called secondary memory page fault refers to a memory page replacement Although the swap file, but it has not been assigned to other programs. In this case the content of the page has not been destroyed, do not read from the swap file in
W This program is switched to the number of stalls replaced
This program is the number of c forced interruption (such as CPU time assigned to exhaustion) of
This program times w voluntary interruption (as if waiting for a particular I / O is finished, such as disk read, etc.)
The number of files I entered this program
Item number O program output
r This program received Socket Message
s This program sent Socket Message
K program signal received (Signal) Number
4, Command Info
Parameter name and instruction execution time C
x instruction end code (Exit Status)
-p or --portability: This option will automatically become the display format setting:
real% e user% Usys% S: The goal is to be compatible with the POSIX specification.
-v or --verbose: This option will be used in all programs of all the resources listed, not only as general English sentences, as well as instructions. To familiarize themselves with the format set or just starting out with this command is useful for people who do not want to spend time.
Examples
1. # time date 2. Sun Mar 26 22:45:34 GMT-8 2006 3. 4. real 0m0.136s 5. user 0m0.010s 6. sys 0m0.070s 7. #
In the example above, execute the command "time date" (see line 1).
System to execute the command "date", the second line as a command "date" of the result.
3-6 Behavior Run "date" time statistics, in the 4th line "real" is the actual time, the fifth line "user" for the user CPU time, line 6 "sys" for the system CPU time.
These three time display formats are MMmNN [.FFF] s.
Use the following command
time -v ps -aux
We can get the results of ps -aux and system resources spent. Information as listed below:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.4 1096 472 ? S Apr19 0:04 init root 2 0.0 0.0 0 0 ? SW Apr19 0:00 [kflushd] root 3 0.0 0.0 0 0 ? SW Apr19 0:00 [kpiod] ...... root 24269 0.0 1.0 2692 996 pts/3 R 12:16 0:00 ps -aux Command being timed: "ps -aux" User time (seconds): 0.05 System time (seconds): 0.06 Percent of CPU this job got: 68% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.16 Average shared text size (kbytes): 0 Average unshared data size (kbytes): 0 Average stack size (kbytes): 0 Average total size (kbytes): 0 Maximum resident set size (kbytes): 0 Average resident set size (kbytes): 0 Major (requiring I/O) page faults: 238 Minor (reclaiming a frame) page faults: 46 Voluntary context switches: 0 Involuntary context switches: 0 Swaps: 0 File system inputs: 0 File system outputs: 0 Socket messages sent: 0 Socket messages received: 0 Signals delivered: 0 Page size (bytes): 4096 Exit status: 0