Linux--- 進程跟蹤手段
strace方法:
strace XXX -o ttt --- 跟蹤XXX執行過程調用的系統調用,結果保存到ttt文件
strace -c XXX --- 跟蹤XXX每次調用系統調用耗費時長
strace -f XXX --- 跟蹤XXX所有進程包括子進程的系統調用
strace -e trace=open,write XXX ---跟蹤XXX執行過程調用的open、write系統調用
strace -e trace=network -p 24567 ---跟24567進程所有與網絡有關的系統調用
ltrace方法:
ltrace –s XXX --- 跟蹤系統調用和庫函數調用
ltrace –e strcpy,strlen XXX --- 跟蹤進程調用的strcpy、strlen兩種庫函數
ltrace -l /lib64/librt.so.1 XXX --- 跟蹤XXX調用的指定動態庫中的庫函數
valgrind方法:
默認沒有安裝,必須手工安裝該工具。
valgrind --tool=memcheck --trace-children=yes XXX
--- 使用valgrind的memcheck工具對XXX命令執行內存檢測。
memcheck
Detects memory errors. It helps you tune your programs to behave correctly.
cachegrind
Profiles cache prediction. It helps you tune your programs to run faster.
callgrind
Works in a similar way to cachegrind but also gathers additional cache-profiling information.
exp-drd
Detects thread errors. It helps you tune your multi-threaded programs to behave correctly.
helgrind
Another thread error detector. Similar to exp-drd but uses different techniques for problem analysis.
massif
A heap profiler. Heap is an area of memory used for dynamic memory allocation.This tool helps you tune your program to use less memory.
lackey
An example tool showing instrumentation basics