Linux--- 进程跟踪手段

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

相关推荐