flamegraph

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

stackcollapse-gdb.pl (1816B)


      1 #!/usr/bin/perl -ws
      2 #
      3 # stackcollapse-gdb  Collapse GDB backtraces
      4 #
      5 # Parse a list of GDB backtraces as generated with the poor man's
      6 # profiler [1]:
      7 #
      8 #   for x in $(seq 1 500); do
      9 #      gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $pid 2> /dev/null
     10 #      sleep 0.01
     11 #    done
     12 #
     13 # [1] http://poormansprofiler.org/
     14 #
     15 # Copyright 2014 Gabriel Corona. All rights reserved.
     16 #
     17 # CDDL HEADER START
     18 #
     19 # The contents of this file are subject to the terms of the
     20 # Common Development and Distribution License (the "License").
     21 # You may not use this file except in compliance with the License.
     22 #
     23 # You can obtain a copy of the license at docs/cddl1.txt or
     24 # http://opensource.org/licenses/CDDL-1.0.
     25 # See the License for the specific language governing permissions
     26 # and limitations under the License.
     27 #
     28 # When distributing Covered Code, include this CDDL HEADER in each
     29 # file and include the License file at docs/cddl1.txt.
     30 # If applicable, add the following below this CDDL HEADER, with the
     31 # fields enclosed by brackets "[]" replaced with your own identifying
     32 # information: Portions Copyright [yyyy] [name of copyright owner]
     33 #
     34 # CDDL HEADER END
     35 
     36 use strict;
     37 
     38 my $current = "";
     39 my $previous_function = "";
     40 
     41 my %stacks;
     42 
     43 while(<>) {
     44   chomp;
     45   if (m/^Thread/) {
     46     $current=""
     47   }
     48   elsif(m/^#[0-9]* *([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)/) {
     49     my $function = $3;
     50     my $alt = $1;
     51     if(not($1 =~ /0x[a-zA-Z0-9]*/)) {
     52       $function = $alt;
     53     }
     54     if ($current eq "") {
     55       $current = $function;
     56     } else {
     57       $current = $function . ";" . $current;
     58     }
     59   } elsif(!($current eq "")) {
     60     $stacks{$current} += 1;
     61     $current = "";
     62   }
     63 }
     64 
     65 if(!($current eq "")) {
     66   $stacks{$current} += 1;
     67   $current = "";
     68 }
     69 
     70 foreach my $k (sort { $a cmp $b } keys %stacks) {
     71   print "$k $stacks{$k}\n";
     72 }