This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gprof/sprof and shared libraries...again


> On Thu, Apr 04, 2002 at 09:00:40AM -0500, Braman, Paul wrote:
> 
>> 
>> This discussion seems to creep up from time to time but I haven't seen
>> anyone post positive results (that I can replicate).
>> 
>> Our RedHat installation here at work is a slightly modified 7.2 (we have a
>> RedHat contractor on-site who's coordinating our setup).  I can't seem to
>> get a profile for a shared library the way I think I should.
>> 
>> First off, what I expect as output from my work is not a profile of the
>> calls *in* the library, but a profile of the calls *to* the library.  (The
>> linker knows what calls are being made to the library and should be able to
>> put timing information around those calls.)
>> 
> 
> 
> Then, you need to compile your work with -g.

I suspect you ment -pg :-)

>> I've got a small library with one function, libprof.so.  I've got a small
>> main that calls an internal function once and a function from the library
>> once.  I can get a profile for the call to the internal function just fine,
>> but nothing I've done has generated information for a call to the function
>> in the library.
>> 
>> Commands I am running...
>> 
>> export LD_PROFILE=libprof.so
>> export LD_PROFILE_OUTPUT=/home/user/proftest
>> g++ -g -fPIC -c -o prof.lo prof.cpp
>> g++ --shared -o libprof.so prof.lo
>> g++ -g -pg -I/home/user/proftest -c -o ptest.o ptest.cpp
>> g++ -pg -o ptest ptest.o -L/home/user/proftest -lprof \
>> -Xlinker -rpath -Xlinker /home/user/proftest
>> /home/user/ptest
>> 
> 
> 
> It profiles libprof.so. That is the calls made from libprof.so.

Well, the functions within libprof.so.

Compiling a file with -pg modifies all functions it contains to record 
both itself and its _caller_ as a pair.  Hence to count the number of 
calls to libprof:foo() you need to have compiled foo() with -pg. 
Profiling the callers won't help.

enjoy,
Andrew





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]