time命令输出信息中的real、user、sys时间

在Linux上,可以用time命令来计算程序执行的时间。

time输出信息中,第一行real的时间标识表示实际感受到的从程序开始执行到程序终止所经过的时间长度,第二行user的时间表示CPU在用户空间执行的时间长度,第三行sys表示CPU在内核空间执行的时间长度。在本次内核编译测试中,统计的时间是time命令输出信息的第一行(用real标识)中的时间长度。

注意第1行和第2、3输出信息的意义是完全不一样的;并非第一行的real就等于后面两行加起来。


Real refers to actual elapsed time; User and Sys refer to CPU time used only by the process.

Real is wall clock time - time from start to finish of the call. This is all elapsed time including time slices used by other processes and time the process spends blocked (for example if it is waiting for I/O to complete).

User is the amount of CPU time spent in user-mode code (outside the kernel) within the process. This is only actual CPU time used in executing the process. Other processes and time the process spends blocked do not count towards this figure.

Sys is the amount of CPU time spent in the kernel within the process. This means executing CPU time spent in system calls within the kernel, as opposed to library code, which is still running in user-space. Like 'user', this is only CPU time used by the process. See below for a brief description of kernel mode (also known as 'supervisor' mode) and the system call mechanism.

User+Sys will tell you how much actual CPU time your process used. Note that this is across all CPUs, so if the process has multiple threads it could potentially exceed the wall clock time reported by Real. Note that in the output these figures include the User and Sys time of all child processes as well, although the underlying system calls return the statistics for the process and its children separately.

请参考:
http://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1

master

Stay hungry, stay foolish.

发表评论

邮箱地址不会被公开。 必填项已用*标注

*