2012年4月5日 星期四

2012年4月1日 星期日

time 的 說明

One of these things is not like the other. 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.



Real 從 下 command 到 看到結果所需要的全部時間
user CPU 在處理 這個 code 所耗的時間
sys cpu 在處理 kernal 的調度所花的時間 例如call library 或是 執行其他的process


在單核心中 如果 Real = User + Sys
但在多核心 且 使用 thread 的情況下
User +Sys 可能 > Real
因為 user 的計算是 每一顆 的時間都 加起來 因此 有兩顆 同時執行五秒 值計算為 10秒



reference 網頁
http://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1