Skip to content

Commit

Permalink
stackcollapse-perf: add streaming mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Corona committed Jul 11, 2022
1 parent 810687f commit 2f6be2f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions stackcollapse-perf.pl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ sub remember_stack {

my $show_inline = 0;
my $show_context = 0;
my $streaming = 0; # stream the stacks without summing them

my $srcline_in_input = 0; # if there are extra lines with source location (perf script -F+srcline)
GetOptions('inline' => \$show_inline,
Expand All @@ -99,7 +100,8 @@ sub remember_stack {
'all' => \$annotate_all,
'tid' => \$include_tid,
'addrs' => \$include_addrs,
'event-filter=s' => \$event_filter)
'event-filter=s' => \$event_filter,
'streaming' => \$streaming)
or die <<USAGE_END;
USAGE: $0 [options] infile > outfile\n
--pid # include PID with process names [1]
Expand All @@ -111,7 +113,8 @@ sub remember_stack {
--context # adds source context to --inline
--srcline # parses output of 'perf script -F+srcline' and adds source context
--addrs # include raw addresses where symbols can't be found
--event-filter=EVENT # event name filter\n
--event-filter=EVENT # event name filter
--streaming # stream the stacks without summing them\n
[1] perf script must emit both PID and TIDs for these to work; eg, Linux < 4.1:
perf script -f comm,pid,tid,cpu,time,event,ip,sym,dso,trace
for Linux >= 4.1:
Expand Down Expand Up @@ -232,7 +235,11 @@ sub inline {
unshift @stack, "";
}
}
remember_stack(join(";", @stack), 1) if @stack;
if ($streaming) {
print join(";", @stack) . " 1\n" if @stack;
} else {
remember_stack(join(";", @stack), 1) if @stack;
}
undef @stack;
undef $pname;
next;
Expand Down Expand Up @@ -425,6 +432,9 @@ sub inline {
}
}

if ($streaming) {
exit(0);
}
foreach my $k (sort { $a cmp $b } keys %collapsed) {
print "$k $collapsed{$k}\n";
}

0 comments on commit 2f6be2f

Please sign in to comment.