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

Compiling the program for use with lprof

Suppose you have a C program that consists of the source files travel.c and misc.c. You must compile your source files with the -ql option to profile a program with lprof:

$ cc -ql -o travel travel.c misc.c

Note that the same -ql option is used to profile a C++ program:

$ CC -ql -o travel travel.C misc.C

When you specify -ql, you arrange for data about your program's run-time behavior to be written to a data file at the end of execution.

If you compile and link your program in separate steps, you must specify -ql when you link as well as when you compile:

   $ cc -ql -c travel.c
   $ cc -ql -c misc.c
   $ cc -ql -o travel travel.o misc.o
See ``Invoking lprof'' for the options you must specify to use the profiler on a program with a name other than a.out.

These command lines illustrate what you must do to profile an entire program. You may be interested in profiling only a piece of a large program. Suppose, for instance, you have run prof on both source files and found out that 70% of the total execution time can be accounted for by one function in travel.c. Now you want to examine that function with lprof to determine how you can improve its performance. To produce profiling data only for travel.c, you enter the commands

   $ cc -ql -c travel.c
   $ cc -c misc.c
   $ cc -ql -o travel travel.o misc.o

Note, finally, that the -ql option overrides the -O option. Therefore, the command

   $ cc -ql -O -o travel travel.c misc.c
will not invoke the optimizer. Of course, you can optimize your program after you have profiled it by recompiling your source files with -O and without -ql.
Next topic: Running the -ql profiled program
Previous topic: Using lprof

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