flamegraph

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

stackcollapse-wcp.pl (1938B)


      1 #!/usr/bin/perl -ws
      2 #
      3 # stackcollapse-wcp  Collapse wallClockProfiler backtraces
      4 #
      5 # Parse a list of GDB backtraces as generated by https://github.com/jasonrohrer/wallClockProfiler
      6 #
      7 # Copyright 2014 Gabriel Corona. All rights reserved.
      8 # Portions Copyright 2020 Ștefan Talpalaru <stefantalpalaru@yahoo.com>
      9 #
     10 # CDDL HEADER START
     11 #
     12 # The contents of this file are subject to the terms of the
     13 # Common Development and Distribution License (the "License").
     14 # You may not use this file except in compliance with the License.
     15 #
     16 # You can obtain a copy of the license at docs/cddl1.txt or
     17 # http://opensource.org/licenses/CDDL-1.0.
     18 # See the License for the specific language governing permissions
     19 # and limitations under the License.
     20 #
     21 # When distributing Covered Code, include this CDDL HEADER in each
     22 # file and include the License file at docs/cddl1.txt.
     23 # If applicable, add the following below this CDDL HEADER, with the
     24 # fields enclosed by brackets "[]" replaced with your own identifying
     25 # information: Portions Copyright [yyyy] [name of copyright owner]
     26 #
     27 # CDDL HEADER END
     28 
     29 use strict;
     30 
     31 my $current = "";
     32 my $start_processing = 0;
     33 my $samples = 0;
     34 my %stacks;
     35 
     36 while(<>) {
     37   s/^\s+|\s+$//g;
     38 
     39   if (m/^Full stacks/) {
     40     $start_processing = 1;
     41     next;
     42   }
     43 
     44   if (not $start_processing) {
     45       next;
     46   }
     47 
     48   if(m/^\d+\.\d+% =+ \((\d+) samples\)/) {
     49     # 99.791% ===================================== (17194 samples)
     50     $samples = $1;
     51     next;
     52   } elsif (m/^\d+: (.*)$/) {
     53     # 1: poll__YNjd8fE6xG8CRNwfLnrx0g_2   (at /mnt/sde1/storage/nim-beacon-chain-clean/vendor/nim-chronos/chronos/asyncloop.nim:343)
     54     my $function = $1;
     55     if ($current eq "") {
     56       $current = $function;
     57     } else {
     58       $current = $function . ";" . $current;
     59     }
     60   } elsif (m/^$/ and $current ne "") {
     61     $stacks{$current} += $samples;
     62     $current = "";
     63   }
     64 }
     65 
     66 foreach my $k (sort { $a cmp $b } keys %stacks) {
     67   print "$k $stacks{$k}\n";
     68 }
     69