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

use function input parameter as period for perf #328

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions stackcollapse-perf.pl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ sub remember_stack {
my $tidy_generic = 1; # clean up function names a little
my $target_pname; # target process name from perf invocation
my $event_filter = ""; # event type filter, defaults to first encountered event
my $period_field = ""; # period field name
my $period_field_warning = 0; # if we printed a warning for the period field
my $event_defaulted = 0; # whether we defaulted to an event (none provided)
my $event_warning = 0; # if we printed a warning for the event

Expand All @@ -99,7 +101,8 @@ sub remember_stack {
'all' => \$annotate_all,
'tid' => \$include_tid,
'addrs' => \$include_addrs,
'event-filter=s' => \$event_filter)
'event-filter=s' => \$event_filter,
'period-field=s' => \$period_field)
or die <<USAGE_END;
USAGE: $0 [options] infile > outfile\n
--pid # include PID with process names [1]
Expand All @@ -111,7 +114,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
--period-field=FIELD # use FIELD as period\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 @@ -250,16 +254,27 @@ sub inline {
# eg, "java 24636/25607 [000] 4794564.109216: 1 cycles:"
# eg, "java 12688/12764 6544038.708352: 10309278 cpu-clock:"
# eg, "V8 WorkerThread 24636/25607 [000] 94564.109216: 100 cycles:"
# eg, "java 12688/12764 6544038.708352: probe_libc:malloc: bytes=0x10"
# other combinations possible
my ($comm, $pid, $tid, $period) = ($1, $2, $3, "");
if (not $tid) {
$tid = $pid;
$pid = "?";
}

if (/:\s*(\d+)*\s+(\S+):\s*$/) {
if (/:\s*(\d+)*\s+(\S+):\s*(.*)$/) {
$period = $1;
my $event = $2;
if ($period_field ne "") {
# if period field is specified, use it
# the value is in hex
if ($3 =~ qr/\b(${period_field})=0x([0-9a-fA-F]+)\b/) {
$period = hex $2;
} elsif ($period_field_warning == 0) {
print STDERR "Period field $period_field not found\n";
$period_field_warning = 1;
}
}

if ($event_filter eq "") {
# By default only show events of the first encountered
Expand Down