From 7b826c0ced9bf32ca17b117784dcf052d80ba108 Mon Sep 17 00:00:00 2001 From: Cosmin Ratiu Date: Tue, 16 Apr 2024 12:29:03 +0300 Subject: [PATCH 1/2] stackcollapse-perf.pl: Add an option to aggregate comm across cpus. Samples produced by perf record can include process names that contain the cpu number in them. For example 'ksoftirqd/32', 'migration/16', etc. Introduce an option called 'aggregate-comm' for replacing the numerical part with '/all' such that the stacks could be combined. This makes flamegraphs for perf records captured on many cpus more legible. Signed-off-by: Cosmin Ratiu --- stackcollapse-perf.pl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/stackcollapse-perf.pl b/stackcollapse-perf.pl index 3ff39bf..44345cb 100755 --- a/stackcollapse-perf.pl +++ b/stackcollapse-perf.pl @@ -88,6 +88,7 @@ sub remember_stack { my $show_inline = 0; my $show_context = 0; +my $aggregate_comm = 0; # replace '/' in input process names with '/all' my $srcline_in_input = 0; # if there are extra lines with source location (perf script -F+srcline) GetOptions('inline' => \$show_inline, @@ -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, + 'aggregate-comm' => \$aggregate_comm) or die < outfile\n --pid # include PID with process names [1] @@ -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 + --aggregate-comm # replace '/' in input process names with '/all'\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: @@ -256,6 +259,12 @@ sub inline { $tid = $pid; $pid = "?"; } + if ($aggregate_comm) { + # Replace per-cpu suffix in process names with '/all'. + # This allows aggregation across multiple CPUs. + # ksoftirqd/156 -> ksoftirqd/all + $comm =~ s/\/\d+/\/all/g; + } if (/:\s*(\d+)*\s+(\S+):\s*$/) { $period = $1; From e577966561cf322ed85eff9e7204f27ba752fccc Mon Sep 17 00:00:00 2001 From: Cosmin Ratiu Date: Tue, 16 Apr 2024 12:29:03 +0300 Subject: [PATCH 2/2] stackcollapse-perf.pl: Add an option to aggregate comm across cpus. Samples produced by perf record can include process names that contain cpu-related suffixes in them. For example 'ksoftirqd/32', 'migration/16', 'kworker/u1025:1', etc. Introduce an option called 'aggregate-comm' for replacing the suffix with '/all' such that related stacks could be combined. This makes flamegraphs for perf records captured on many cpus more legible. Signed-off-by: Cosmin Ratiu --- stackcollapse-perf.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stackcollapse-perf.pl b/stackcollapse-perf.pl index 44345cb..43566ec 100755 --- a/stackcollapse-perf.pl +++ b/stackcollapse-perf.pl @@ -88,7 +88,7 @@ sub remember_stack { my $show_inline = 0; my $show_context = 0; -my $aggregate_comm = 0; # replace '/' in input process names with '/all' +my $aggregate_comm = 0; # replace '/' in input process names with '/all' my $srcline_in_input = 0; # if there are extra lines with source location (perf script -F+srcline) GetOptions('inline' => \$show_inline, @@ -114,7 +114,7 @@ sub remember_stack { --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 - --aggregate-comm # replace '/' in input process names with '/all'\n + --aggregate-comm # replace '/' in input process names with '/all'\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: @@ -263,7 +263,7 @@ sub inline { # Replace per-cpu suffix in process names with '/all'. # This allows aggregation across multiple CPUs. # ksoftirqd/156 -> ksoftirqd/all - $comm =~ s/\/\d+/\/all/g; + $comm =~ s/\/.+/\/all/g; } if (/:\s*(\d+)*\s+(\S+):\s*$/) {