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! Best, Charles -- Um ax?! :) -- Charles Novaes de Santana, PhD http://www.imedea.uib-csic.es/~charles [[alternative HTML version deleted]]
On 12/02/2014 01: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!Hi Charles Section 3.4 of RShowDoc("R-exts") discusses some options; I've had luck with operf & friends. Remember to compile without optimizations and with debugging information -ggdb -O0. (I think this is appropriate for the R-devel mailing list http://www.r-project.org/posting-guide.html#which_list) Martin Morgan> > Best, > > Charles >-- Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793
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
Thank you very much for the tips, Martin and Duncan! Rprof and operf are helping me a lot!! Also, I am now in R-dev maillist and I see there seems to be more appropriate to this kind of question. Best, Charles On Wed, Dec 3, 2014 at 12:03 AM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:> 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 >-- Um ax?! :) -- Charles Novaes de Santana, PhD http://www.imedea.uib-csic.es/~charles [[alternative HTML version deleted]]