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

标签 filter valgrind call-graph

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

我生成了输出:

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 等库的调用。

n.b.:我一直试图找出无用的库,但这充其量似乎很麻烦且不完整。

非常感谢您提前回答。

最佳答案

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

http://sourceforge.net/mailarchive/forum.php?thread_name=e847e3a9-0d10-4c5e-929f-51258ecf9dfc%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;
    }
}

关于从 valgrind 的 callgrind 输出过滤对 libc 的调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7761448/

相关文章:

python - 根据日期键的值过滤字典

php - 使用 PHP 和 MySQL 查询的网站过滤器

c++ - getaddrinfo 内存泄漏

C token 循环段错误问题

javascript - 基于 JS 文件/片段的调用图创建器

filter - 将新字段添加到来自 Netflix Zuul 预过滤器的请求正文

css - 如何重置或覆盖 IE CSS 过滤器?

c++ - 我的析构函数似乎没有命中树中的每个节点,因为我有内存泄漏,我在这里错过了什么?

java - 如何生成 Java 调用图,基于 Eclipse 的解决方案