From rfrancois at mango-solutions.com  Sat Mar 31 22:31:49 2007
From: rfrancois at mango-solutions.com (Romain Francois)
Date: Sat, 31 Mar 2007 21:31:49 +0100
Subject: [Rd] Probem with argument "append" in "Rprof"
Message-ID: <460EC535.600@mango-solutions.com>

Hello,

Appending information to the profiler's output seems to generate
problems. Here is a small example of code :

<code r>
require(boot)
Rprof( memory.profiling = TRUE)
Rprof(NULL)
for(i in 1:2){
  Rprof( memory.profiling = TRUE, append = TRUE)
  example(boot)
  Rprof(NULL)
}
</code>

The problem is that the file Rprof.out contains more than once the
header information:

$ grep "sample.interval=" Rprof.out
memory profiling: sample.interval=20000
memory profiling: sample.interval=20000
memory profiling: sample.interval=20000

and `summaryRprof` or `R CMD Rprof` are not dealing with it

> idx <- grep( "sample", rownames( smp <- summaryRprof()[[1]] ) );
smp[idx, ]
                      self.time self.pct total.time total.pct
sample.interval=20000         0        0       0.04       0.1

`sample.interval=20000` is incorrectly considered as a function.


This is not too much of a big deal, but then if I ask for memory
profiling information as well, I get nothing:

> summaryRprof( mem = "stats")
Error in tapply(1:1L, list(index = c("sample.interval=20000:profiling:",  :
        arguments must have same length
> summaryRprof( mem = "tseries")
Error in data.frame(..., check.names = FALSE) :
        arguments imply differing number of rows: 1, 1490
> summaryRprof( mem = "both")
Error in apply(sapply(strsplit(memstuff, ":"), as.numeric), 1, diff) :
        dim(X) must have a positive length

$ R CMD Rprof Rprof.out

Each sample represents  seconds.
Total run time: 0 seconds.

Total seconds: time spent in function and callees.
Self seconds: time spent in function alone.

   %       total       %       self
 total    seconds     self    seconds    name
Illegal division by zero at /usr/local/lib/R/bin/Rprof line 91, <> line
1491.
                         
A quick fix could be to ignore all the lines containing sample.interval=
except the first one, but then if someone wants to actually change the
interval argument in Rprof, it would not be correct. I attach a patch
against R-devel/src/library/utils/R/summRprof.R to do that anyway, but I
will look at a better solution.

I am not fluent enough in Perl to do the same in the Rprof script, it
looks like it does not handle the memory profiling information anyway. I
am about to learn Perl, so I guess it could be a useful way to do it. I
also attach a patch against R-devel/src/scripts/Rprof that would at
least get rid of the memory profiling information (if any). This is not
as good as dealing with it, but ... this is the first time I ever touch
a Perl script.


Cheers,

Romain



> version
              
_                                                              
platform      
i686-pc-linux-gnu                                              
arch          
i686                                                           
os            
linux-gnu                                                      
system         i686,
linux-gnu                                                
status         Under development
(unstable)                                   
major         
2                                                              
minor          6.0                                  
year          
2007                                                           
month         
03                                                             
day           
30                                                             
svn rev       
40983                                                          
language      
R                                                              
version.string R version 2.6.0 Under development (unstable) (2007-03-30
r40983)

-- 
Mango Solutions
data analysis that delivers

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: summRprof.patch
Type: text/x-patch
Size: 770 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20070331/bed20353/attachment.bin 


[Rd] Probem with argument "append" in "Rprof"
Romain Francois