Unit testing framework
Memory check
valgrind
参考:
博客
文档
可以使用PostScript查看图形化结果
Performance analyzer
Oracle Developer Studio:
timer
1 | $ /usr/bin/time -p ls |
Or,
1 | $ time ls |
其中(参考链接),
1 | $ type -a time |
CPU时间
Function’s CPU time:
* 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](https://stackoverflow.com/questions/15760447/what-is-the-meaning-of-incl-cpu-time-excl-cpu-time-incl-real-cpu-time-excl-re/74426370).
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.
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?
debug tool
gdb
1 | (gdb) breakpoint exit |
Enable coredump: how to do
1 | ulimit -c unlimited |
Where is the core dumped file:
1 | grep 'kernel.core_pattern' /etc/sysctl.conf |
strace
Example:
1 | strace -f -o strace.log -tt -y -yy -e trace=desc,process,network |
Refer to here
-e trace=ipc – communication between processes (IPC)
-e trace=memory – memory syscalls
-e trace=network – network syscalls
-e trace=process – process calls (like fork, exec)
-e trace=signal – process signal handling (like HUP, exit)
-e trace=file – file related syscalls
-e trace=desc – all file descriptor related system calls