从valgrind的callgrind输出中过滤对libc的调用 [英] Filter calls to libc from valgrind's callgrind output

查看:148
本文介绍了从valgrind的callgrind输出中过滤对libc的调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to generate a call graph for a server for documentation purposes. Not for any kind of profiling.

我使用以下命令生成了输出:

I generated the output with:

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

并转换为: http://code.google.com/p/jrfonseca/Wiki/Gprof2Dot 转换为.dot文件,但这包含太多信息,无法用作文档.

and converted with: http://code.google.com/p/jrfonseca/wiki/Gprof2Dot to a .dot file, but this contains way too much info to be useful as documentation.

我想过滤掉对libc,libstdc ++,libtcl,libhwloc之类的库的调用.

I would like to filter out the calls to libraries such as libc, libstdc++, libtcl, libhwloc and whatnot.

n.b .:我一直试图只是将无用的库grep出来,但这充其量似乎是繁琐和不完整的.

n.b.: I've been trying to just grep out the useless libraries, but that seems cumbersome and incomplete at best.

非常感谢您提前回答.

推荐答案

在这里震耳欲聋的沉默之后,实际上在我问的所有地方,我都转向valgrind-users @ ML.这是线程:

After the deafening silence here, and actually everywhere I asked, I turned to the valgrind-users@ ML. Here's the thread:

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

Josef的回复非常有帮助,在#perl的耐心帮助下,我整理了一个脚本来帮助我过滤掉呼叫图中不需要的库.

Josef's reply was extremely helpful, and with a lot of patience from #perl I have put together a script helps me filter out libraries I don't need in my call-graph.

该脚本依赖于告诉callgrind更加冗长:

The script relies on telling callgrind to be extra verbose:

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

这样,它将生成字符串而不是参考数字,从而使其更易于解析:

This way it will produce strings instead of reference numbers, making it much easier parsable:

#!/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;
    }
}

这篇关于从valgrind的callgrind输出中过滤对libc的调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆