stackcollapse-instruments.pl 514 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/perl -w
  2. #
  3. # stackcollapse-instruments.pl
  4. #
  5. # Parses a CSV file containing a call tree as produced by XCode
  6. # Instruments and produces output suitable for flamegraph.pl.
  7. #
  8. # USAGE: ./stackcollapse-instruments.pl infile > outfile
  9. use strict;
  10. my @stack = ();
  11. <>;
  12. foreach (<>) {
  13. chomp;
  14. /\d+\.\d+ms[^,]+,(\d+(?:\.\d*)?),\s+,(\s*)(.+)/ or die;
  15. my $func = $3;
  16. my $depth = length ($2);
  17. $stack [$depth] = $3;
  18. foreach my $i (0 .. $depth - 1) {
  19. print $stack [$i];
  20. print ";";
  21. }
  22. print "$func $1\n";
  23. }