从 valgrind 的 callgrind 输出过滤对 libc 的调用



我正试图为文档目的生成服务器的调用图。用于任何类型的分析。

我生成的输出是:

sudo valgrind --tool=callgrind --dump-instr=yes /opt/ats-trunk/bin/traffic_server

并使用:http://code.google.com/p/jrfonseca/wiki/Gprof2Dot转换为。dot文件,但其中包含的信息太多,无法作为文档使用。

我想过滤掉对libbc, libstdc++, libtcl, libhwloc等库的调用。

的被害者。:我一直在试图找出无用的库,但这似乎很麻烦,而且不完整。

提前感谢您的回答

在这里和实际上我问的每个地方都是震耳欲聋的沉默之后,我转向了valgrind-users@ ML。

http://sourceforge.net/mailarchive/forum.php?thread_name=e847e3a9 - 0 - d10 - 4 - c5e - 929 f - 51258 ecf9dfc%40iris& forum_name = valgrind-users

Josef的回复非常有帮助,在#perl的耐心帮助下,我编写了一个脚本,帮助我过滤掉调用图中不需要的库。

脚本依赖于告诉callgrind额外的冗长:

valgrind --tool=callgrind --dump-instr=yes --compress-pos=no 
  --compress-strings=no /opt/ats-trunk/bin/traffic_server

这样它将生成字符串而不是引用数,使其更容易被解析:

#!/usr/bin/perl
use Modern::Perl;
require File::Temp;
my $cob = qr{^cob=/(?:usr/)?lib};
my $ob = qr{^ob=/(?:usr/)?lib/};
my $calls = qr{^calls=};
open (my $fh, '<', $ARGV[0]) or die $!;
my $tmp = File::Temp->new(UNLINK => 1);
## Skip all external libraries, as defined by $ob
while (readline $fh) {
    if (/$ob/ ) {
        # skip the entire ob= section we don't need.
        0 while defined($_ = readline $fh) && !/^ob=/;
        # put the last line back, we read too far
        seek($fh, -length($_), 1);
    } else {
        print $tmp $_;
    }
}
close ($fh);
## Skip all calls to external libraries, as defined by $cob
my $tmpname = $tmp->filename;
open ($tmp, '<', $tmpname) or die $!;
while (readline $tmp) {
    if (/$cob/) {
        # skip until we find a line starting with calls=
        # skip that line too
        0 while defined($_ = readline $tmp) && !/$calls/;
        # then we skip until we either hit ^word= or an empty line.
        # In other words: skip all lines that start with 0x
        0 while defined($_ = readline $tmp) && /^0x/;
        # put the last line back, we read too far
        seek($tmp, -length($_), 1);
    }  else {
       print;
    }
}

最新更新