|
|
The steps for compiling a program for timing profiling are basically the same as those described for lprof.
To arrange for timing and function call count data
to be written to a
data file at the end of execution,
you must compile your source files
with the -p (or -qp) option to profile a program with
prof.
Using the same example described previously:
$ cc -p -o travel travel.c misc.c
The same -p (or -qp) option is used to profile
a C++ program:
$ CC -p -o travel travel.C misc.C
As noted earlier, if you compile and link your program in separate steps, you must specify -p when you link as well as when you compile:
$ cc -p -c travel.c $ cc -p -c misc.c $ cc -p -o travel travel.o misc.oAlternatively, if recompiling your program is not convenient, you can use fur to insert profiling code into your objects.
$ fur -P prof.o -p all travel.o $ fur -P prof.o -p all misc.o $ cc -p -o travel travel.o misc.oSee ``Invoking prof'' for the options you must specify to use the profiler on a program with a name other than a.out.
As with lprof, you can gather data for parts of a program by only compiling the relevant source with the -p option. Note that you may still see timing information for functions defined in the "non-profiled" source, but no call count data will be produced.
$ cc -p -c travel.c $ cc -c misc.c $ cc -p -o travel travel.o misc.oIn this case, no call count information will be produced for functions defined in misc.c but any timing signals caught while executing such functions will be reported.