flamegraph

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

stackcollapse-instruments.pl (680B)


      1 #!/usr/bin/perl -w
      2 #
      3 # stackcollapse-instruments.pl
      4 #
      5 # Parses a file containing a call tree as produced by XCode Instruments
      6 # (Edit > Deep Copy) and produces output suitable for flamegraph.pl.
      7 #
      8 # USAGE: ./stackcollapse-instruments.pl infile > outfile
      9 
     10 use strict;
     11 
     12 my @stack = ();
     13 
     14 <>;
     15 foreach (<>) {
     16 	chomp;
     17 	/\d+\.\d+ (?:min|s|ms)\s+\d+\.\d+%\s+(\d+(?:\.\d+)?) (min|s|ms)\t \t(\s*)(.+)/ or die;
     18 	my $func = $4;
     19 	my $depth = length ($3);
     20 	$stack [$depth] = $4;
     21 	foreach my $i (0 .. $depth - 1) {
     22 		print $stack [$i];
     23 		print ";";
     24 	}
     25 
     26 	my $time = 0 + $1;
     27 	if ($2 eq "min") {
     28 		$time *= 60*1000;
     29 	} elsif ($2 eq "s") {
     30 		$time *= 1000;
     31 	}
     32 
     33 	printf("%s %.0f\n", $func, $time);
     34 }