性能指标
CPU 时间
函数调用的 CPU 时间:
Inclusive time: total cpu time, include all functions it calls.Exclusive time: only the time used by the function itself, exclusive all its children.
Refer to
here.
Wall time: total time the process used, containing IO time.
CPU usage (CPU 利用率) = CPU time / Wall time.
real/user/system time
- 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.
Refer to
here.- Real is wall clock time - time from start to finish of the call. This is all elapsed time
CPU 时间可能大于墙上时间:
这是因为 CPU 时间是所有 CPU 核的运行时间的累加和,墙上时间则是实际的时间。此时 CPU 利用率大于
100%. (这是自己的理解)TODO: Is CPU time in flame graph sum of all the CPU time? Or is it the wall time when CPU
works?
计时工具:time
1 | $ /usr/bin/time -p ls |
Or,
1 | $ time ls |
其中(参
考链接),
1 | $ type -a time |