Skip to content

Probem with argument "append" in "Rprof"

1 message · Romain Francois

#
[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
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:
Error in tapply(1:1L, list(index = c("sample.interval=20000:profiling:",  :
        arguments must have same length
Error in data.frame(..., check.names = FALSE) :
        arguments imply differing number of rows: 1, 1490
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
_
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)