[Rd] graphic for the R profiler

From: Romain Francois <rfrancois_at_mango-solutions.com>
Date: Sat, 30 Jun 2007 07:07:44 +0100


((resent without the generated links, thanks Dirk))

Hello all,

I just wanted to share a small perl script that generates a dot file from the result of the R profiler. The dot file can than be used to create a graphical display of the profiling. You can save this file in the bin directory of your R installation and then create a graph, for example an SVG by piping the output of the script to dot:

$ R CMD Rprof2dot Rprof.out | dot -Tsvg > test3.svg

Some example graphics are presented in the R wiki here: http://wiki.r-project.org/rwiki/doku.php?id=tips:misc:profiling

Cheers,

Romain

<code perl>
#! /usr/bin/perl

use Getopt::Long;

my $cutoff=5;
GetOptions ('cutoff=s' => \$cutoff );

%calltree = ();
%allfun = ();

while (<>) {

   if (/^sample\.interval=/) {

   	s/sample\.interval=//;
   	$sample = $_ / 1e6;
   } else {
	  chomp;
	  @line = reverse split(/ /);
	
     $caller = shift(@line);
     $allfun{$caller}++;
     while( $called = shift(@line) ){
       $allfun{$called}++;
       $calltree{$caller}{$called} ++ ;
       $caller = $called;
     }

   }
}

print "digraph {\n" ;
print 'graph [ rankdir = "LR"]; '."\n";
foreach $fun (keys %allfun){

   $_ = $fun;
   s/"$//;
   $value = $allfun{$fun} ;
   print "$fun [shape=rect,fontsize=6,label=$_\\n(".$value.")\"] \n" if $value > ($cutoff-1) ;
}

foreach $caller (keys %calltree){

   for $called ( keys %{ $calltree{$caller} } ) {

     $value = $calltree{$caller}{$called} ;
     $n1 = $allfun{$called} ;
     $n2 = $allfun{$caller} ;

     print " $caller -> $called [label=" . $value. ",fontsize=6]\n" if ( 
$value > $cutoff );

   }
}
print "}\n"
</code>

-- 
Mango Solutions
data analysis that delivers

Tel:  +44(0) 1249 467 467
Fax:  +44(0) 1249 467 468
Mob:  +44(0) 7813 526 123

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sat 30 Jun 2007 - 06:10:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 30 Jun 2007 - 06:35:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.