OK,所以这不是什么秘密,strace产生庞大的数量输出。(我知道有多种选项可以稍微过滤输出。)
是否有任何工具可以将原始strace日志处理为更易读的内容?
我在寻找什么样的“解码”?好吧,按设计strace在非常低的水平上工作。我正在寻找可以总结最重要观点的东西。例如,FD 4 可能在不同的时刻指向不同的文件;让机器而不是我来跟踪它会很有用。PID 也是如此。我希望能够在跟踪中的不同时刻看到进程树,等等。GUI 工具会很棒,但如果它使事情更容易理解,即使是基于文本的工具也是可以接受的。
strace有一个-c开关,可以为您提供所进行的各种系统调用的摘要报告。
-c Count time, calls, and errors for each system call and report a \n summary on program exit. On Linux, this attempts to show system \n time (CPU time spent running in the kernel) independent of wall \n clock time. If -c is used with -f or -F (below), only aggregate \n totals for all traced processes are kept.\nRun Code Online (Sandbox Code Playgroud)\n\n$ strace -c systemctl list-unit-files --type=service\n...\n...\n% time seconds usecs/call calls errors syscall\n------ ----------- ----------- --------- --------- ----------------\n 51.81 0.001831 1831 1 waitid\n 8.15 0.000288 7 39 mmap\n 7.89 0.000279 19 15 read\n 6.11 0.000216 8 26 mprotect\n 4.56 0.000161 11 15 open\n 2.91 0.000103 103 1 connect\n 2.24 0.000079 79 1 clone\n 2.15 0.000076 38 2 statfs\n 2.01 0.000071 4 19 close\n 1.95 0.000069 5 13 poll\n 1.90 0.000067 5 14 2 recvmsg\n 1.70 0.000060 4 16 fstat\n 0.88 0.000031 8 4 3 stat\n 0.82 0.000029 29 1 socket\n 0.65 0.000023 8 3 munmap\n 0.57 0.000020 5 4 sendto\n 0.42 0.000015 5 3 ioctl\n 0.40 0.000014 7 2 lstat\n 0.40 0.000014 7 2 sendmsg\n 0.34 0.000012 4 3 brk\n 0.23 0.000008 8 1 pipe\n 0.23 0.000008 4 2 fcntl\n 0.20 0.000007 4 2 rt_sigaction\n 0.20 0.000007 7 1 1 access\n 0.20 0.000007 4 2 geteuid\n 0.17 0.000006 6 1 execve\n 0.14 0.000005 5 1 getsockname\n 0.11 0.000004 4 1 dup2\n 0.11 0.000004 4 1 getresuid\n 0.11 0.000004 4 1 getresgid\n 0.11 0.000004 4 1 arch_prctl\n 0.08 0.000003 3 1 rt_sigprocmask\n 0.08 0.000003 3 1 getrlimit\n 0.08 0.000003 3 1 set_tid_address\n 0.08 0.000003 3 1 set_robust_list\n 0.00 0.000000 0 4 write\n 0.00 0.000000 0 1 kill\n------ ----------- ----------- --------- --------- ----------------\n100.00 0.003534 207 6 total\nRun Code Online (Sandbox Code Playgroud)\n\n我发现这个 Perl 脚本的名字Strace_analyzer.pl听起来像你正在寻找的。
$ ./strace_analyzer_ng_0.03.pl -help\nUsage: strace-analyze [OPTION]\xe2\x80\xa6 [FILE]\nAnalyzes strace output for IO functions. It creates statistics\non IO functions and performance of the read and write functions.\nThe strace file should have been run with \xe2\x80\x98strace -tt [PROGRAM]\nRun Code Online (Sandbox Code Playgroud)\n\n我上面链接的页面上有一个输出示例。这里发帖太长了。我也在pastebin.com 上发布了这里。
\n\n\n\n我遇到了这个应用程序ioapps,它可以让您更直观地了解应用程序运行时正在执行的操作。也许这可能比处理日志更适合您想要完成的任务strace。
\n\n\n示例 GUI \n\n\n\nRun Code Online (Sandbox Code Playgroud)\n\n$ ioprofiler-trace thunderbird\n加载后,我们只需关闭 Thunderbird 窗口并检查是否有名为“ioproftrace.log”的跟踪日志,因为这是日志的默认名称(可以使用 -o 命令行指定另一个名称)选项):
\n\nRun Code Online (Sandbox Code Playgroud)\n\n$ ls -l ioproftrace.log \n -rw-r--r-- 1 user user 74890554 Apr 4 22:04 ioproftrace.log\n看起来没问题,所以我们可以对其运行 ioprofiler:
\n\nRun Code Online (Sandbox Code Playgroud)\n$ ioprofiler ioproftrace.log \n
注意:该项目strace+不再被维护,事实上它的许多功能已strace通过-k开关合并到默认值中。因此,您可能需要确保您的版本strace至少达到 4.9,这是合并该开关的时间。
-k Print the execution stack trace of the traced processes after \n each system call (experimental).\nRun Code Online (Sandbox Code Playgroud)\n\n strace+ 项目页面摘录\n\n\n\nstrace+ 是 strace 的改进版本,它收集与每个系统调用相关的堆栈跟踪。由于系统调用需要昂贵的用户内核上下文切换,因此它们通常是性能瓶颈的根源。strace+ 允许程序员进行更详细的系统调用分析,并确定哪些调用站点导致了昂贵的系统调用,因此具有优化的潜力。
\n