flamegraph

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

stackcollapse-vtune.pl (3174B)


      1 #!/usr/bin/perl -w
      2 #
      3 # stackcollapse-vtune.pl
      4 #
      5 # Parses the CSV file containing a call tree from Intel VTune hotspots profiler and produces an output suitable for flamegraph.pl.
      6 #
      7 # USAGE: perl stackcollapse-vtune.pl infile > outfile
      8 #
      9 # WORKFLOW:
     10 #
     11 # This assumes you have Intel VTune installed and on path (using Command Line)
     12 #
     13 # 1. Profile C++ application tachyon_find_hotspots (example shipped with Intel VTune 2013):
     14 #
     15 #    amplxe-cl -collect hotspots -r result_vtune_tachyon -- ./tachyon_find_hotspots
     16 #
     17 # 2. Export raw VTune data to csv file:
     18 #
     19 ##### VTune 2013 & 2015
     20 #   amplxe-cl -R top-down -report-out result_vtune_tachyon.csv -filter "Function Stack" -format csv -csv-delimiter comma -r result_vtune_tachyon
     21 #### VTune 2016
     22 #		amplxe-cl.exe -R top-down -call-stack-mode all -column="CPU Time:Self","Module" -report-output result_vtune_tachyon.csv -filter "Function Stack" -format csv -csv-delimiter comma -r result_vtune_tachyon
     23 #
     24 # 3. Generate a flamegraph:
     25 #
     26 #    perl stackcollapse-vtune result_vtune_tachyon.csv | perl flamegraph.pl > result_vtune_tachyon.svg
     27 #
     28 # AUTHOR: Rohith Bakkannagari
     29 
     30 use strict;
     31 
     32 # data initialization
     33 my @stack = ();
     34 my $rowCounter = 0; #flag for row number
     35 
     36 my $numArgs = $#ARGV + 1;
     37 if ($numArgs != 1)
     38 {
     39 print "$ARGV[0]\n";
     40 print "Usage : stackcollapse-vtune.pl <out.cvs> > out.txt\n";
     41 exit;
     42 }
     43 
     44 my $inputCSVFile = $ARGV[0];
     45 my $funcOnly = '';
     46 my $depth = 0;
     47 my $selfTime = 0;
     48 my $dllName = '';
     49 
     50 open(my $fh, '<', $inputCSVFile) or die "Can't read file '$inputCSVFile' [$!]\n";
     51 
     52 while (my $currLine = <$fh>){
     53 	$rowCounter = $rowCounter + 1;
     54 	# to discard first row which typically contains headers
     55 	next if $rowCounter == 1;
     56 	chomp $currLine;
     57 
     58 	### VTune 2013 & 2015
     59 	#VTune - sometimes the call stack information is enclosed in double quotes (?).  To remove double quotes.  Not necessary for XCode instruments (MAC)
     60 	$currLine =~ s/\"//g;
     61 	$currLine =~ /(\s*)(.*),(.*),.*,([0-9]*\.?[0-9]+)/ or die "Error in regular expression on the current line\n";
     62 	$dllName = $3;
     63 	$func = $dllName.'!'.$2; # Eg : m_lxe.dll!MathWorks::lxe::IrEngineDecorator::Apply
     64 	$depth = length ($1);
     65 	$selfTime = $4*1000; # selfTime in msec
     66 	### VTune 2013 & 2015
     67 
     68 	### VTune 2016
     69 	# $currLine =~ /(\s*)(.*?),([0-9]*\.?[0-9]+?),(.*)/ or die "Error in regular expression on the current line $currLine\n";
     70 	#  if ($2 =~ /\"/)
     71 	#  {
     72 	# 	$currLine =~ /(\s*)\"(.*?)\",([0-9]*\.?[0-9]+?),(.*)/ or die "Error in regular expression on the current line $currLine\n";
     73 	#  	$funcOnly = $2;
     74 	#  	$depth = length ($1);
     75 	#  	$selfTime = $3*1000; # selfTime in msec
     76 	#  	$dllName = $4;
     77 	#  }
     78 	#  else
     79 	#  {
     80 	#  	$funcOnly = $2;
     81 	#  	$depth = length ($1);
     82 	#  	$selfTime = $3*1000; # selfTime in msec
     83 	#  	$dllName = $4;
     84 	#  }
     85 	#  my $func = $dllName.'!'.$funcOnly; # Eg : m_lxe.dll!MathWorks::lxe::IrEngineDecorator::Apply
     86 	 ### VTune 2016
     87 
     88 	my $tempString = '';
     89 	$stack [$depth] = $func;
     90 	foreach my $i (0 .. $depth - 1) {
     91 		$tempString = $tempString.$stack[$i].";";
     92 	}
     93 	$tempString = $tempString.$func." $selfTime\n";
     94 	if ($selfTime != 0){
     95 		print "$tempString";
     96 	}
     97 }