flamegraph

Fork of flamegraph without j***s*****
git clone git://git.laack.co/flamegraph.git
Log | Files | Refs | README

stackcollapse-aix.pl (1185B)


      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 
      9 use strict;
     10 
     11 my $process = "";
     12 my $current = "";
     13 my $previous_function = "";
     14 
     15 my %stacks;
     16 
     17 while(<>) {
     18   chomp;
     19   if (m/^\d+:/) {
     20     if(!($current eq "")) {
     21       $current = $process . ";" . $current;
     22       $stacks{$current} += 1;
     23       $current = "";
     24     }
     25     m/^\d+: ([^ ]*)/;
     26     $process = $1;
     27     $current = "";
     28   }
     29   elsif(m/^---------- tid# \d+/){
     30     if(!($current eq "")) {
     31       $current = $process . ";" . $current;
     32       $stacks{$current} += 1;
     33     }
     34     $current = "";
     35   }
     36   elsif(m/^(0x[0-9abcdef]*) *([^ ]*) ([^ ]*) ([^ ]*)/) {
     37     my $function = $2;
     38     my $alt = $1;
     39     $function=~s/\(.*\)?//;
     40     if($function =~ /^\[.*\]$/) {
     41       $function = $alt;
     42     }
     43     if ($current) {
     44       $current = $function . ";" . $current;
     45     }
     46     else {
     47       $current = $function;
     48     }
     49   }
     50 }
     51 
     52 if(!($current eq "")) {
     53   $current = $process . ";" . $current;
     54   $stacks{$current} += 1;
     55   $current = "";
     56   $process = "";
     57 }
     58 
     59 foreach my $k (sort { $a cmp $b } keys %stacks) {
     60   print "$k $stacks{$k}\n";
     61 }