Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding line numbers to perf output breaks stackcollapse-perf.pl #205

Open
Hi-Angel opened this issue May 4, 2019 · 3 comments
Open

Adding line numbers to perf output breaks stackcollapse-perf.pl #205

Hi-Angel opened this issue May 4, 2019 · 3 comments

Comments

@Hi-Angel
Copy link

Hi-Angel commented May 4, 2019

Sometimes it's hard to navigate code without having line numbers in source. This is especially relevant for Vala-based apps, as they tend to mangle function names in various ways. So I'm trying to add srcline column to perf script, so that I'd have in flamegraph line numbers, but this breaks flamegraph.

Steps to reproduce (in terms of terminal commands)

$ perf record -g --sample-cpu ls
$ perf script -F+srcline | stackcollapse-perf.pl

Expected

Script finishes with no warnings or errors

Actual

Lots of

Unrecognized line:   ld-2.29.so[11634] at /usr/bin/stackcollapse-perf.pl line 339, <> line 50.
@SyamGadde
Copy link

I recognize this is actually not a failing of FlameGraph, so maybe it belongs somewhere else... but I too would love to know if there is a way to get perf (or some other profiler) to record stack traces with line numbers in a way that FlameGraph can use them. The -F+srcline above doesn't really give me line numbers anyway, otherwise I would be able to massage the output to send to stackcollapse-perf.pl.

@stefantalpalaru
Copy link
Contributor

I found a way to filter the output of perf script -F +srcline so it's compatible with "stackcollapse-perf.pl" - "filter-perf-script.pl":

#!/usr/bin/env perl

use strict;
use warnings;

my $prev_line = "";
my $line_info;

while(<>) {
    if(/^  \S+/ and $prev_line =~ /\+0x/) {
        $line_info = $_;
        $line_info =~ s/^\s+//;
        $line_info =~ s/\s+$//;
        $line_info =~ s/^(\S+)/|$1|/;

        $prev_line =~ s/\+0x/$line_info+0x/;
    }
    if(not $prev_line =~ /^  \S+/) {
        print($prev_line);
    }
    $prev_line = $_;
}
print($prev_line);

And I use it like this:

perf record --call-graph dwarf,16000 ...
perf script -F +srcline | ./filter-perf-script.pl > out.perf
./stackcollapse-perf.pl out.perf > perf_collapsed.txt
./flamegraph.pl perf_collapsed.txt > perf.svg

@marxin
Copy link

marxin commented Feb 21, 2021

I see this feature as very handy! The @stefantalpalaru's patch works fine, but I would prefer to display the location only on hover, it makes the report less readable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants