[R-SIG-Mac] profiling C shared libraries loaded into R

Michael Braun braunm at MIT.EDU
Sat Jun 13 23:58:11 CEST 2009


Simon:

Sorry, please disregard my last email.  Shark was crashing because  
some of something with Shark, not R.  But unfortunately, the Unknown  
Libraries remain.

Here is how I compiled R.  In the config.site file, I set:

R_PAPERSIZE=letter
R_BATCHSAVE=--no-save
CC='gcc-4.2 -arch x86_64 -m64 -march=core2 -msse3 -g -pg -O2'
OBJC='gcc-4.2 -arch x86_64 -m64 -march=core2 -msse3 -g -pg -O2'
DEFS=-DHAVE_INLINE
F77='gfortran -arch x86_64 -g -pg -O2'
LIBnn=lib
CXX='g++-4.2 -arch x86_64 -march=core2 -p -pg -O2'
FC='gfortran -arch x86_64 -m64 -march=core2 -g -pg -O2'
TCLTK_LIBS=/usr/lib

To configure, I ran the following script

#!/bin/bash

./configure \
SHELL='/bin/bash' \
r_arch=x86_64 \
--with-system-zlib \
--with-blas='-framework vecLib' --with-lapack='-framework vecLib' \
--with-ICU \
--with-aqua \
--enable-R-framework \
--enable-BLAS-shlib \
--with-x \
--with-readline=/usr/local \
--with-tcltk \
--with-iconv=no \
--with-cairo \
--disable-R-profiling \
--with-recommended-packages=no


Any idea what I did wrong?

Thanks,

Michael



On Jun 12, 2009, at 7:27 PM, Simon Urbanek wrote:

> Michael,
>
> On Jun 12, 2009, at 4:20 PM, Michael Braun wrote:
>
>> Hi.  I have a shared library that I would like to profile.  I see  
>> that this issue has been touched on in some previous posts, but I  
>> am still having trouble, and I am hoping someone here can help.
>>
>> First things first...  I am running R 2.8.0 patched on OS X 10.5.7,  
>> on a dual quad-core Mac Pro.   It is the 64-bit binary build for  
>> Leopard, as downloaded from CRAN.
>>
>> I am compiling my code using gcc-4.2, and I am including the -g -p - 
>> pg flags.
>
> The -p -pg part (they are mutually-exclusive aren't they? so you get  
> just -pg) won't really help unless you also compile R that way since  
> the gprof initialization happens in the executable, not in the  
> library (and don't forget it at link time).
>
>
>> Optimization is turned off (-O0).
>
> Just to make sure - using PKG_CFLAGS doesn't have the desired  
> effect, because R's -O2 will override it, so better be sure that the  
> optimization is off. If you run the steps manually, make sure you  
> have -g (and -pg if you wish) everywhere.
>
>
>> I AM able to debug the code using gdb (called as R -d gdb).  I  
>> always run R from the command line.
>>
>> I have tried profiling using Shark, which recognizes functions in  
>> libR.dylib, but none of the functions in mylib.so.  For each  
>> function call, Shark refers to "Unknown Library", and after the  
>> function address, there is an indicator of [unknown].  Also, when I  
>> use Shark, it appears to want to profile the entire R session.  All  
>> I care about is my library.
>>
>
> I'm unable to replicate that. Shark correctly recognizes the  
> function and the loaded library for me. Try using default flags -  
> they do include -g -O2 (which worked for me).
>
>
>> I am also open to using gprof instead, but I cannot find the  
>> requisite gmon.out file.
>>
>
> See above - you won't find it unless you compile R with -pg since  
> the gprof init code must be in the executable (more precisely you  
> don't have to re-compile the entire R with that, it should be  
> sufficient to use -pg in the link step for exec/R).
>
> Cheers,
> Simon
>
>
>> Thanks in advance for any suggestions.
>>
>> Michael
>>
>>
>>
>> -------------------------------------------
>> Michael Braun
>> Homer A. Burnell Career Development Professor, and
>> 	Assistant Professor of Management Science (Marketing Group)
>> MIT Sloan School of Management
>> One Amherst St., E40-169
>> Cambridge, MA 02142
>> braunm at mit.edu
>> 617-253-3436
>>
>> _______________________________________________
>> R-SIG-Mac mailing list
>> R-SIG-Mac at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>>
>>
>

-------------------------------------------
Michael Braun
Homer A. Burnell Career Development Professor, and
	Assistant Professor of Management Science (Marketing Group)
MIT Sloan School of Management
One Amherst St., E40-169
Cambridge, MA 02142
braunm at mit.edu
617-253-3436



More information about the R-SIG-Mac mailing list