Skip to content

Commit

Permalink
Update Xcode Instruments converter to handle Deep Copy format
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrhynas committed May 18, 2022
1 parent 810687f commit be363ff
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions stackcollapse-instruments.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
}

0 comments on commit be363ff

Please sign in to comment.