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
本文介绍了三种用于跟踪系统调用的重要工具:strace、ltrace及valgrind的使用方法。通过这些工具,可以详细了解程序运行过程中所涉及的系统调用及库函数调用情况,从而帮助开发者定位和解决程序中可能存在的问题。
8002

被折叠的 条评论
为什么被折叠?



