[R] Profiling a C/C++ library from R

Duncan Murdoch murdoch.duncan at gmail.com
Wed Dec 3 00:03:21 CET 2014


On 02/12/2014, 4:43 PM, Charles Novaes de Santana wrote:
> Dear all,
> 
> I am running a c++ library (a .so file) from a R code. I am using the
> function dyn.load("lib.so") to load the library. Do you know a way to
> profile my C library from R? Or should I compile my C library as an
> executable and profile it using the typical C-profilers?
> 
> Thanks in advance for any help!

If you want line-level profiling of your C++ code, you'll certainly need
to use something that's not built in to R.  You can probably do it
without recompiling your C++ code, just by profiling the R process.  But
the details certainly depend on the profiler you choose to use.

If you just want to know how much time is being spent in each C++
function called from R, Rprof() should be able to tell you.  (It might
give misleading information if your C++ code takes too long to execute,
and some timer ticks get lost; I'm not sure if the underlying code takes
account of that.)

Duncan Murdoch



More information about the R-help mailing list