2011-10-13 63 views
3

我試圖爲服務器生成文檔的調用圖。 不是用於任何類型的分析。從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文件,但是這包含了太多的信息是作爲文檔有用。

我想過濾掉庫,如libc,libstdC++,libtcl,libhwloc和whatnot的調用。

n.b .:我一直在試圖只想出無用的庫,但看起來很麻煩和不完整。

非常感謝您提前給出答案。

回答

7

在這裏震耳欲聾的沉默之後,實際上到處都是我問,我轉向valgrind-users @ ML。這裏的線程:

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

約瑟夫的回答是非常有益的,並與#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; 
    } 
}