flamegraph

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

stackcollapse-faulthandler.pl (1638B)


      1 #!/usr/bin/perl -ws
      2 #
      3 # stackcollapse-faulthandler  Collapse Python faulthandler backtraces
      4 #
      5 # Parse a list of Python faulthandler backtraces as generated with
      6 # faulthandler.dump_traceback_later.
      7 #
      8 # Copyright 2014 Gabriel Corona. All rights reserved.
      9 # Copyright 2017 Jonathan Kolb. All rights reserved.
     10 #
     11 # CDDL HEADER START
     12 #
     13 # The contents of this file are subject to the terms of the
     14 # Common Development and Distribution License (the "License").
     15 # You may not use this file except in compliance with the License.
     16 #
     17 # You can obtain a copy of the license at docs/cddl1.txt or
     18 # http://opensource.org/licenses/CDDL-1.0.
     19 # See the License for the specific language governing permissions
     20 # and limitations under the License.
     21 #
     22 # When distributing Covered Code, include this CDDL HEADER in each
     23 # file and include the License file at docs/cddl1.txt.
     24 # If applicable, add the following below this CDDL HEADER, with the
     25 # fields enclosed by brackets "[]" replaced with your own identifying
     26 # information: Portions Copyright [yyyy] [name of copyright owner]
     27 #
     28 # CDDL HEADER END
     29 
     30 use strict;
     31 
     32 my $current = "";
     33 
     34 my %stacks;
     35 
     36 while(<>) {
     37   chomp;
     38   if (m/^Thread/) {
     39     $current=""
     40   }
     41   elsif(m/^  File "([^"]*)", line ([0-9]*) in (.*)/) {
     42     my $function = $1 . ":" . $2 . ":" . $3;
     43     if ($current eq "") {
     44       $current = $function;
     45     } else {
     46       $current = $function . ";" . $current;
     47     }
     48   } elsif(!($current eq "")) {
     49     $stacks{$current} += 1;
     50     $current = "";
     51   }
     52 }
     53 
     54 if(!($current eq "")) {
     55   $stacks{$current} += 1;
     56   $current = "";
     57 }
     58 
     59 foreach my $k (sort { $a cmp $b } keys %stacks) {
     60   print "$k $stacks{$k}\n";
     61 }