aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/flame-graph/stackcollapse-instruments.pl
blob: fb017b9a1e0ad6910bd49ff7d0f35595757159a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/perl -w
#
# stackcollapse-instruments.pl
#
# Parses a CSV file containing a call tree as produced by XCode
# Instruments and produces output suitable for flamegraph.pl.
#
# USAGE: ./stackcollapse-instruments.pl infile > outfile

use strict;

my @stack = ();

<>;
foreach (<>) {
	chomp;
	/\d+\.\d+ms[^,]+,(\d+(?:\.\d*)?),\s+,(\s*)(.+)/ or die;
	my $func = $3;
	my $depth = length ($2);
	$stack [$depth] = $3;
	foreach my $i (0 .. $depth - 1) {
		print $stack [$i];
		print ";";
	}
	print "$func $1\n";
}