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

Michael Braun braunm at MIT.EDU
Sat Jun 13 23:31:45 CEST 2009


Simon:

Thanks for your suggestion.  I recompiled R 2.9.0, including the -g  
and -pg flags everywhere.  I still do not see a gmon.out file in my  
working directory.  And now, Shark crashes as soon as it start  
analyzing the samples.  This occurs with any R job, not just my own  
shared lib.

Is there a way I can look after the fact to see if R was compiled  
correctly to support profiling?

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