DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Analyzing run-time behavior

Profiling archive or shared object library code with lprof

You can use lprof to profile archive library code as long as you specify -ql when you compile the library source files, and again when you link the library with your program:

   $ cc -ql -c function1.c function2.c
   $ ar -r libfoo.a function1.o function2.o
   $ cc -c test1.c
   $ cc -dn -ql -o test1 -L. test1.o -lfoo
   $ test1

Profiling data for the library functions are written to the data file test1.cnt. The command

   $ lprof -c test1.cnt
generates the default lprof output for the profiled archive library.

To profile test1 as well as the library code, you specify -ql when you compile test1.c. Profiling data for both the library code and the test program are written to test1.cnt.

You can profile shared object library code with lprof by specifying -ql when you compile and link the library functions, and again when you link the library with your program. Note that if you are not profiling the test program, you must specify -g when you compile the source:

   $ cc -K PIC -ql -c function1.c function2.c
   $ cc -ql -G -o libfoo.so function1.o function2.o
   $ cc -g -c test1.c
   $ cc -ql -o test1 -L. test1.o -lfoo
   $ LD_LIBRARY_PATH=. export LD_LIBRARY_PATH
   $ test1
Profiling data for the library functions are written to the data file libfoo.so.cnt. Profiling data for archive library functions are stored in a data file that takes its name from the program, whereas profiling data for shared library functions are stored in a data file that takes its name from the library. Profiling data for archive library functions are stored in the same data file as profiling data for the program, while profiling data for shared library functions are stored in a different data file.
If you specify -ql when you compile test1.c, two data files would have been created: test1.cnt and libfoo.so.cnt. Whether or not you profile the test program, you specify
   $ lprof -c libfoo.so.cnt
to generate lprof default output for the profiled shared library.

Note that because profiling data for shared library functions are stored in a data file that takes its name from the library, you can obtain merged output for multiple test runs of a shared library even though the library was linked with a different executable each time. Consider the following commands:

   $ mv libfoo.so.cnt libfoo.cnt
   $ cc -g -c test2.c
   $ cc -ql -o test2 -L. test2.o -lfoo
   $ test2
   $ lprof -d merged.cnt -m libfoo.cnt libfoo.so.cnt

The data files libfoo.cnt and libfoo.so.cnt can be merged because both were created by executing the programs test1 and test2 that used libfoo.so.

For a discussion of how libraries are created and linked with your program, see ``Link editing''.


Next topic: Profiling C++ programs with lprof
Previous topic: Merged data

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005