[forgot to attach the second patch in the first mail, sorry.]

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


--- summRprof.R	2007-03-31 21:10:31.000000000 +0100
+++ /tmp/R-devel/src/library/utils/R/summRprof.R	2006-10-05 07:54:38.000000000 +0100
@@ -32,10 +32,8 @@
     repeat({
 
        chunk<-readLines(filename,n=chunksize)
-       chunk <- chunk[ -grep("sample\\.interval=", chunk) ]     
        if (length(chunk)==0)
            break
-           
        if (memory.profiling){
            memprefix<-attr(regexpr(":[0-9]+:[0-9]+:[0-9]+:[0-9]+:",chunk),"match.length")
            if (memory=="both"){
@@ -121,7 +119,6 @@
     repeat({
 
        chunk<-readLines(filename,n=chunksize)
-       chunk <- chunk[ -grep("sample\\.interval=", chunk) ]     
        if (length(chunk)==0)
            break
        memprefix<-attr(regexpr(":[0-9]+:[0-9]+:[0-9]+:[0-9]+:",chunk),

--- Rprof	2007-03-31 21:23:16.000000000 +0100
+++ /tmp/R-devel/src/scripts/Rprof	2007-03-31 19:58:29.000000000 +0100
@@ -57,12 +57,11 @@
 %totalcounts = ();
 
 while (<>) {
-    if (/.*sample\.interval=/) {
-	s/.*sample\.interval=//;
+    if (/^sample\.interval=/) {
+	s/sample\.interval=//;
 	$sample = $_ / 1e6;
     } else {
 	chomp;
-  s/[^\"]*\"/"/;
 	@line = split(/ /);
 	%names = ();
 	$leaf = @line[0];
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to