1

as suggest by Dirk Eddelbuettel in this talk and this answer I tried to profile compiled R code using gperftools. Here is what I did.

I used Dirks profilingSmall.R as script that I want to profile. I repeat it here:

## R Extensions manual, section 3.2 'Profiling R for speed'
## 'N' reduced to 99 here
suppressMessages(library(MASS))
suppressMessages(library(boot))
storm.fm <- nls(Time ~ b*Viscosity/(Wt - c), stormer, start = c(b=29.401, c=2.2183))
st <- cbind(stormer, fit=fitted(storm.fm))
storm.bf <- function(rs, i) {
    st$Time <-  st$fit + rs[i]
    tmp <- nls(Time ~ (b * Viscosity)/(Wt - c), st, start = coef(storm.fm))
    tmp$m$getAllPars()
}
rs <- scale(resid(storm.fm), scale = FALSE) # remove the mean
Rprof("boot.out")
storm.boot <- boot(rs, storm.bf, R = 99) # pretty slow
Rprof(NULL)

To profile it I run the following script

LD_PRELOAD="/usr/lib/libprofiler.so.0" 
\CPUPROFILE=sample.log \
Rscript profilingSmall.R

Then I tried to parse the log file using

pprof /usr/bin/R sample.log

This returned the following error

Using local file /usr/bin/R.
Using local file sample.log.
substr outside of string at /usr/local/bin/pprof line 3618.
Use of uninitialized value in string eq at /usr/local/bin/pprof line 3618.
substr outside of string at /usr/local/bin/pprof line 3620.
Use of uninitialized value in string eq at /usr/local/bin/pprof line 3620.
sample.log: header size >= 2**16

sample.log is empty. However, a bunch of sample.log_digit were created that contain information that looks reasonable.

Community
  • 1
  • 1
Julian Karch
  • 444
  • 4
  • 20

2 Answers2

3

I had the same problem, but realized my problem. I'd done:

export CPUPROFILE=test.prof
export LD_PRELOAD="/usr/local/lib/libprofiler.so"
testprog ...
pprof --web `which testprog` test.prof

If I stopped after running testprog the prof files wasn't empty but after pprof it was. pprof crashed with the substr error.

What I realized later was that by setting and exporting LD_PRELOAD that libprofiler.so was also loaded for pprof, overwriting test.prof. You just need to ensure LD_PRELOAD is not set when you run pprof.

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
0

I'm using gperftools-2.5, and I also encountered the same problem:

[root@localhost ivrserver]# pprof --text ./IvrServer ivr.prof
Using local file ./IvrServer.
Using local file ivr.prof.
substr outside of string at /usr/local/bin/pprof line 3695.
Use of uninitialized value in string eq at /usr/local/bin/pprof line 3695.
substr outside of string at /usr/local/bin/pprof line 3697.
Use of uninitialized value in string eq at /usr/local/bin/pprof line 3697.
ivr.prof: header size >= 2**16

I found this is because the prof file (ivr.prof in my example) is empty.

everytime the profiler start and end, it will create a new prof file, you should use xxx.prof.0 xxx.prof.1 ... to get the right result

CSchulz
  • 10,882
  • 11
  • 60
  • 114
Robert Lee
  • 86
  • 1
  • 4