stackcollapse-bpftrace.pl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. use strict;
  46. my @stack;
  47. my $in_stack = 0;
  48. foreach (<>) {
  49. chomp;
  50. if (!$in_stack) {
  51. if (/^@\[/) {
  52. $in_stack = 1;
  53. }
  54. } else {
  55. if (m/^\]: (\d+)/) {
  56. print join(';', reverse(@stack)) . " $1\n";
  57. $in_stack = 0;
  58. @stack = ();
  59. } else {
  60. push(@stack, $_);
  61. }
  62. }
  63. }