stackcollapse-aix.pl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/perl -ws
  2. #
  3. # stackcollapse-aix Collapse AIX /usr/bin/procstack backtraces
  4. #
  5. # Parse a list of backtraces as generated with the poor man's aix-perf.pl
  6. # profiler
  7. #
  8. use strict;
  9. my $process = "";
  10. my $current = "";
  11. my $previous_function = "";
  12. my %stacks;
  13. while(<>) {
  14. chomp;
  15. if (m/^\d+:/) {
  16. if(!($current eq "")) {
  17. $current = $process . ";" . $current;
  18. $stacks{$current} += 1;
  19. $current = "";
  20. }
  21. m/^\d+: ([^ ]*)/;
  22. $process = $1;
  23. $current = "";
  24. }
  25. elsif(m/^---------- tid# \d+/){
  26. if(!($current eq "")) {
  27. $current = $process . ";" . $current;
  28. $stacks{$current} += 1;
  29. }
  30. $current = "";
  31. }
  32. elsif(m/^(0x[0-9abcdef]*) *([^ ]*) ([^ ]*) ([^ ]*)/) {
  33. my $function = $2;
  34. my $alt = $1;
  35. $function=~s/\(.*\)?//;
  36. if($function =~ /^\[.*\]$/) {
  37. $function = $alt;
  38. }
  39. if ($current) {
  40. $current = $function . ";" . $current;
  41. }
  42. else {
  43. $current = $function;
  44. }
  45. }
  46. }
  47. if(!($current eq "")) {
  48. $current = $process . ";" . $current;
  49. $stacks{$current} += 1;
  50. $current = "";
  51. $process = "";
  52. }
  53. foreach my $k (sort { $a cmp $b } keys %stacks) {
  54. print "$k $stacks{$k}\n";
  55. }