1

I am trying to profile a R script with the last (third) approach in http://pj.freefaculty.org/blog/?p=140. I wonder if what I do (described in the following) is correct?

Firstly, in my.cpp, the link says to add #include <gperftools/profiler.h>, which doesn't work for me. I found that the header is located in a different dir, and what works for me is #include <google/profiler.h>.

Then I put the following around some code to be profiled

ProfilerStart("./myprofile.log") 
//the part of the code to be profiled
ProfilerStop()

Next, I created a script mytest.R, which contains the following

Sys.setenv("PKG_LIBS"="-lprofiler")
sourceCpp('my.cpp') #  for compiling the cpp file
... (use some functions defined in my.cpp

Lastly, when I run in bash

$ R -f mytest.R

it runs a R session, run the content of mytest.R inside R, and exit R after outputting

PROFILE: interrupts/evictions/bytes = 353/0/1988

Does it mean the profiling was run successfully, or not? "interrupts" and "evictions" look troublesome to me.

It does generate the profiling output to myprofile.log, with

$ google-pprof --text /usr/bin/R myprofile.log 

I can see

Total: 353 samples
      37  10.5%  10.5%       37  10.5% b313b2cb
      21   5.9%  16.4%       21   5.9% b313b2b8
      18   5.1%  21.5%       18   5.1% b313b2ce
      15   4.2%  25.8%       15   4.2% _IO_str_pbackfail
      10   2.8%  28.6%       10   2.8% b69be532
       9   2.5%  31.2%        9   2.5% b69be520
       7   2.0%  33.1%        7   2.0% b69bd111
       6   1.7%  34.8%        6   1.7% b313b2dc
       6   1.7%  36.5%        6   1.7% b69bd132
       5   1.4%  38.0%        5   1.4% b69bb50f
       5   1.4%  39.4%        5   1.4% b69bb6d8
       4   1.1%  40.5%        4   1.1% b3133bda
       4   1.1%  41.6%        4   1.1% b3134c2b
       4   1.1%  42.8%        4   1.1% b313b298
       4   1.1%  43.9%        4   1.1% b69bd159
       3   0.8%  44.8%        3   0.8% b3134c32
       3   0.8%  45.6%        3   0.8% b313b29b
       3   0.8%  46.5%        3   0.8% b313b2c8
       3   0.8%  47.3%        3   0.8% b69bb6e0
       3   0.8%  48.2%        3   0.8% b69bb6f1
       3   0.8%  49.0%        3   0.8% b69bcef1
       3   0.8%  49.9%        3   0.8% b69bd100

No entry in the last column is human-readable, so I wonder if some way to make them readable?

I wonder if I miss something? Thanks!

3
  • It's probably just a binary with stripped symbols. Commented May 20, 2014 at 11:25
  • How would you retain the symbols that are readable? Thanks. Commented May 20, 2014 at 12:28
  • I would start small. Build a standalone C++ programs with g++, see that perftools works. Then deal with R. For the Debian/Ubuntu package symbols are in an extra package r-base-core-dbg; that works with gdb and may help here. I haven't had time for a worked example, but as I told you on your earlier question my (older) HPC slides cover this... Commented May 20, 2014 at 12:30

1 Answer 1

1

Instead of

google-pprof --text /usr/bin/R myprofile.log

if you issue sourceCpp with verbose=T you'll see the file path and generated object file...

Building shared library
--------------------------------------------------------

DIR: /tmp/RtmpyxYB19/sourcecpp_79831e029f

/usr/lib/R/bin/R CMD SHLIB -o 'sourceCpp_2.so' --->8---

so try using (in this instance)

google-pprof --text /tmp/RtmpyxYB19/sourcecpp_79831e029f/sourceCpp_2.so myprofile.log
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.