[Rcpp-devel] Profiling Rcpp compiled through sourceCpp or cxxfunction

Luke.Domanski at csiro.au Luke.Domanski at csiro.au
Sun Feb 16 20:28:51 CET 2014


Apologies for bumping a post, but I still remain frustrated.

I have not been able to find a sufficient solution to this in the Achieves that isn't preceded with "Use Google perftools". So I assume lack of response is not due to my ignorance of an easily discoverable solution  in the Achieves.

Surely we should be able to profile Rcpp code with other profilers out there, and not limit people to use of Google Perftools. Again, any help with the following would be appreciated.

>
> Hi All,
>
> I am trying to profile some Rcpp code, and have tried using Solaris Studios and Intel Vtune with little success.
>
> I have found the info re. Google perftools here http://dirk.eddelbuettel.com/papers/ismNov2009introHPCwithR.pdf and here http://stackoverflow.com/questions/13224322/profiling-rcpp-code-on-os-x but would prefer to find a more generic solution applicable to a number of profiler products (note: I have not tried the perftools solution yet, if nobody has an alternative solution I'll will install and try perftools) .
>
> We have compiled a version of R 3.0.2 with both debug+profiling flags (i.e. -g -pg) and profiling only (i.e. -pg).
>
> Solarise Studio can  profile with only the debugger information. While vtune relies on a profiling compilation I believe.
>
> As an example, take:
> $:> cat ProfilingTest.cpp
> #include <math.h>
> #include <Rcpp.h>
>
> void shortFunc(Rcpp::NumericVector x,
>                Rcpp::NumericVector y) {
>
>     Rcpp::NumericVector temp(x.size());
>
>     for (unsigned int j = 0; j < x.size(); j++) {
>         temp[j]=sqrt(x[j]/y[j]);
>     }
> }
>
> void lengthyFunc(Rcpp::NumericVector x,
>                  Rcpp::NumericVector y) {
>
>     Rcpp::NumericVector temp(x.size());
>
>     for (unsigned int i = 0; i < 1000; i++) {
>         for (unsigned int j = 0; j < x.size(); j++) {
>             temp[j]=sqrt(x[j]/y[j]);
>         }
>     }
> }
>
> // [[Rcpp::export]]
> void testfunc(SEXP x, SEXP y){
>
>     Rcpp::NumericVector v1(x);
>     Rcpp::NumericVector v2(y);
>
>     for (unsigned int i=0; i<100; i++){
>         shortFunc(v1,v2);
>         lengthyFunc(v1,v2);
>     }
> }
>
> To get a profile (and similarly debug) version of the Rcpp code using either sourceCpp or cxxfunction I do the following in R run through the profiler product's interrogation process:
> > require(Rcpp)
> > Sys.setenv("-pg")
> > sourceCpp("ProfilingTest.cpp")
> > testfunc(rnorm(10000),rnorm(10000))
> > q("no")
>
> OR
>
> > require(inline)
> > require(Rcpp)
> > myplugin=getPlugin("Rcpp")
> > myplugin$env$PKG_CXXFLAGS<-"-pg"
> > testfunc<-cxxfunction(signature(x="numeric",y="numeric"), includes=readLines("ProfilingTest.cpp"), body="testfunc(x,y);", settings=myplugin)
> > testfunc(rnorm(10000),rnorm(10000))
> > q("no")
>
> When viewing the profiler results however, both profilers I tried give a single, non descriptive, entry for the call to testfunc(), where the functions names would otherwise be listed. Something along the lines of:
> <sourceCpp_XXXX.so> - No functions found
>
> and similarly for the file produced by cxxfunction . This gives you no more information than running the code with Rprof(), which assigns all the C++ time to the <Anonymous> tag/function.
>
> With Solaris Studios I even used "collect -A copy R" to automatically copy and archive the loaded ".so" files of the program together with the raw profile results, so that the temporary sourceCPP_xxxx.so with profiling file should be available during the analysis/viewing stage (analyzer program), but no luck.
>
> Can anyone see something obvious the I am doing wrong here? Could it be that functions inside the Rcpp source are simply being optimized out in favour of inlined code? Surely you would at least see the one entry point function to the .so file.
>
> Any help from someone who has done this successfully would be appreciated.
>
> Cheers,
> Luke Domanski.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140216/3e1d1bba/attachment.html>


More information about the Rcpp-devel mailing list