-tt 在每行輸出的前面,顯示毫秒級別的時間 -T 顯示每次系統調用所花費的時間 -v 對於某些相關調用,把完整的環境變數,檔案stat結構等打出來. -f 跟蹤目標進程,以及目標進程創建的所有子進程. -e 控制要跟蹤的事件和跟蹤行為,比如指定要跟蹤的系統調用名稱. trace=file 跟蹤和檔案訪問相關的調用(參數中有檔案名) trace=process 和進程管理相關的調用,比如fork/exec/exit_group trace=network 和網絡通信相關的調用,比如socket/sendto/connect trace=signal 信號發送和處理相關,比如kill/sigaction trace=desc 和檔案描述符相關,比如write/read/select/epoll等 trace=ipc 進程見通信相關,比如shmget等 -o 把strace的輸出單獨寫到指定的檔案 -s 當系統調用的某個參數是字元串時,最多輸出指定長度的內容,預設是32個位元組. -p 指定要跟蹤的進程pid,要同時跟蹤多個pid,重複多次-p選項即可.
strace -tt -T -v -f -e trace=file -o ~/strace.log.2 -s 1024 -p 25849
strace -v ps -e 2
strace -v ls
neo@netkiller:~/workspace/Document$ strace -c ls Docbook makedoc Tex % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- -nan 0.000000 0 11 read -nan 0.000000 0 1 write -nan 0.000000 0 38 13 open -nan 0.000000 0 27 close -nan 0.000000 0 25 fstat -nan 0.000000 0 39 mmap -nan 0.000000 0 16 mprotect -nan 0.000000 0 4 munmap -nan 0.000000 0 3 brk -nan 0.000000 0 2 rt_sigaction -nan 0.000000 0 1 rt_sigprocmask -nan 0.000000 0 2 ioctl -nan 0.000000 0 9 9 access -nan 0.000000 0 1 execve -nan 0.000000 0 1 fcntl -nan 0.000000 0 2 getdents -nan 0.000000 0 1 getrlimit -nan 0.000000 0 1 statfs -nan 0.000000 0 1 arch_prctl -nan 0.000000 0 3 1 futex -nan 0.000000 0 1 set_tid_address -nan 0.000000 0 1 set_robust_list ------ ----------- ----------- --------- --------- ---------------- 100.00 0.000000 190 23 total
neo@netkiller:~/workspace/Document$ strace -f -e open ls >/dev/null open("/etc/ld.so.cache", O_RDONLY) = 3 open("/lib/librt.so.1", O_RDONLY) = 3 open("/lib/libselinux.so.1", O_RDONLY) = 3 open("/lib/libacl.so.1", O_RDONLY) = 3 open("/lib/libc.so.6", O_RDONLY) = 3 open("/lib/libpthread.so.0", O_RDONLY) = 3 open("/lib/libdl.so.2", O_RDONLY) = 3 open("/lib/libattr.so.1", O_RDONLY) = 3 open("/proc/filesystems", O_RDONLY) = 3 open("/usr/lib/locale/locale-archive", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/locale.alias", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_IDENTIFICATION", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_IDENTIFICATION", O_RDONLY) = 3 open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_MEASUREMENT", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_MEASUREMENT", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_TELEPHONE", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_TELEPHONE", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_ADDRESS", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_ADDRESS", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_NAME", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_NAME", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_PAPER", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_PAPER", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_MESSAGES", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_MESSAGES", O_RDONLY) = 3 open("/usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_MONETARY", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_MONETARY", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_COLLATE", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_COLLATE", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_TIME", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_TIME", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_NUMERIC", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_NUMERIC", O_RDONLY) = 3 open("/usr/lib/locale/en_US.UTF-8/LC_CTYPE", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/locale/en_US.utf8/LC_CTYPE", O_RDONLY) = 3 open(".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3