是否有一个简单的工具,或者是否有一种方法可以将 strace 输出转换为可以可视化或更容易筛选的东西?我必须弄清楚应用程序哪里出了问题,但是跟踪它会产生大量数据。试图更大规模地跟踪这个应用程序及其线程正在做什么(或试图做什么)被证明是很难读取每个系统调用的。
我没有任何预算,我们是一家纯 Linux 商店。
If your problem is a network one, you could try to limit the strace output to the network related syscalls with a
strace -e trace=network your_program
是的,使用-c
参数来可视化每个系统调用的计数时间、调用和错误,并以表格的形式报告摘要,例如
$ strace -c -fp $(pgrep -n php)
Process 11208 attached
^CProcess 11208 detached
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
83.78 0.112292 57 1953 152 stat
7.80 0.010454 56 188 lstat
7.79 0.010439 28 376 access
0.44 0.000584 0 5342 32 recvfrom
0.15 0.000203 0 3985 sendto
0.04 0.000052 0 27184 gettimeofday
0.00 0.000000 0 6 write
0.00 0.000000 0 3888 poll
------ ----------- ----------- --------- --------- ----------------
100.00 0.134024 42922 184 total
这将在不分析大量数据的情况下识别问题。
另一种方法是通过特定的系统调用(例如recvfrom
/ sendto
)进行过滤,以可视化接收和发送的数据,例如调试 PHP 进程:
strace -e recvfrom,sendto -fp $(pgrep -n php) -s 1000 2>&1 | while read -r line; do
printf "%b" $line;
done | strings