stackcollapse-bpftrace.pl (1901B)
1 #!/usr/bin/perl -w 2 # 3 # stackcollapse-bpftrace.pl collapse bpftrace samples into single lines. 4 # 5 # USAGE ./stackcollapse-bpftrace.pl infile > outfile 6 # 7 # Example input: 8 # 9 # @[ 10 # _raw_spin_lock_bh+0 11 # tcp_recvmsg+808 12 # inet_recvmsg+81 13 # sock_recvmsg+67 14 # sock_read_iter+144 15 # new_sync_read+228 16 # __vfs_read+41 17 # vfs_read+142 18 # sys_read+85 19 # do_syscall_64+115 20 # entry_SYSCALL_64_after_hwframe+61 21 # ]: 3 22 # 23 # Example output: 24 # 25 # entry_SYSCALL_64_after_hwframe+61;do_syscall_64+115;sys_read+85;vfs_read+142;__vfs_read+41;new_sync_read+228;sock_read_iter+144;sock_recvmsg+67;inet_recvmsg+81;tcp_recvmsg+808;_raw_spin_lock_bh+0 3 26 # 27 # Copyright 2018 Peter Sanford. All rights reserved. 28 # 29 # This program is free software; you can redistribute it and/or 30 # modify it under the terms of the GNU General Public License 31 # as published by the Free Software Foundation; either version 2 32 # of the License, or (at your option) any later version. 33 # 34 # This program is distributed in the hope that it will be useful, 35 # but WITHOUT ANY WARRANTY; without even the implied warranty of 36 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 # GNU General Public License for more details. 38 # 39 # You should have received a copy of the GNU General Public License 40 # along with this program; if not, write to the Free Software Foundation, 41 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 42 # 43 # (http://www.gnu.org/copyleft/gpl.html) 44 # 45 46 use strict; 47 48 my @stack; 49 my $in_stack = 0; 50 51 foreach (<>) { 52 chomp; 53 if (!$in_stack) { 54 if (/^@\[$/) { 55 $in_stack = 1; 56 } elsif (/^@\[,\s(.*)\]: (\d+)/) { 57 print $1 . " $2\n"; 58 } 59 } else { 60 if (m/^,?\s?(.*)\]: (\d+)/) { 61 if (length $1) { 62 push(@stack, $1); 63 } 64 print join(';', reverse(@stack)) . " $2\n"; 65 $in_stack = 0; 66 @stack = (); 67 } else { 68 $_ =~ s/^\s+//; 69 push(@stack, $_); 70 } 71 } 72 }