From be363ff521ebf92b8836c8a44cc4c3c02d933e0e Mon Sep 17 00:00:00 2001 From: Jayson Rhynas Date: Wed, 18 May 2022 13:21:20 -0400 Subject: [PATCH] Update Xcode Instruments converter to handle Deep Copy format --- stackcollapse-instruments.pl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/stackcollapse-instruments.pl b/stackcollapse-instruments.pl index fb017b9a..3cbaa87b 100755 --- a/stackcollapse-instruments.pl +++ b/stackcollapse-instruments.pl @@ -2,8 +2,8 @@ # # stackcollapse-instruments.pl # -# Parses a CSV file containing a call tree as produced by XCode -# Instruments and produces output suitable for flamegraph.pl. +# Parses a file containing a call tree as produced by XCode Instruments +# (Edit > Deep Copy) and produces output suitable for flamegraph.pl. # # USAGE: ./stackcollapse-instruments.pl infile > outfile @@ -14,13 +14,21 @@ <>; foreach (<>) { chomp; - /\d+\.\d+ms[^,]+,(\d+(?:\.\d*)?),\s+,(\s*)(.+)/ or die; - my $func = $3; - my $depth = length ($2); - $stack [$depth] = $3; + /\d+\.\d+ (?:min|s|ms)\s+\d+\.\d+%\s+(\d+(?:\.\d+)?) (min|s|ms)\t \t(\s*)(.+)/ or die; + my $func = $4; + my $depth = length ($3); + $stack [$depth] = $4; foreach my $i (0 .. $depth - 1) { print $stack [$i]; print ";"; } - print "$func $1\n"; + + my $time = 0 + $1; + if ($2 eq "min") { + $time *= 60*1000; + } elsif ($2 eq "s") { + $time *= 1000; + } + + printf("%s %.0f\n", $func, $time); }