gprof: Executing
1
1 3 Executing the Program
1 ***********************
1
1 Once the program is compiled for profiling, you must run it in order to
1 generate the information that 'gprof' needs. Simply run the program as
1 usual, using the normal arguments, file names, etc. The program should
1 run normally, producing the same output as usual. It will, however, run
1 somewhat slower than normal because of the time spent collecting and
1 writing the profile data.
1
1 The way you run the program--the arguments and input that you give
1 it--may have a dramatic effect on what the profile information shows.
1 The profile data will describe the parts of the program that were
1 activated for the particular input you use. For example, if the first
1 command you give to your program is to quit, the profile data will show
1 the time used in initialization and in cleanup, but not much else.
1
1 Your program will write the profile data into a file called
1 'gmon.out' just before exiting. If there is already a file called
1 'gmon.out', its contents are overwritten. There is currently no way to
1 tell the program to write the profile data under a different name, but
1 you can rename the file afterwards if you are concerned that it may be
1 overwritten.
1
1 In order to write the 'gmon.out' file properly, your program must
1 exit normally: by returning from 'main' or by calling 'exit'. Calling
1 the low-level function '_exit' does not write the profile data, and
1 neither does abnormal termination due to an unhandled signal.
1
1 The 'gmon.out' file is written in the program's _current working
1 directory_ at the time it exits. This means that if your program calls
1 'chdir', the 'gmon.out' file will be left in the last directory your
1 program 'chdir''d to. If you don't have permission to write in this
1 directory, the file is not written, and you will get an error message.
1
1 Older versions of the GNU profiling library may also write a file
1 called 'bb.out'. This file, if present, contains an human-readable
1 listing of the basic-block execution counts. Unfortunately, the
1 appearance of a human-readable 'bb.out' means the basic-block counts
1 didn't get written into 'gmon.out'. The Perl script 'bbconv.pl',
1 included with the 'gprof' source distribution, will convert a 'bb.out'
1 file into a format readable by 'gprof'. Invoke it like this:
1
1 bbconv.pl < bb.out > BH-DATA
1
1 This translates the information in 'bb.out' into a form that 'gprof'
1 can understand. But you still need to tell 'gprof' about the existence
1 of this translated information. To do that, include BB-DATA on the
1 'gprof' command line, _along with 'gmon.out'_, like this:
1
1 gprof OPTIONS EXECUTABLE-FILE gmon.out BB-DATA [YET-MORE-PROFILE-DATA-FILES...] [> OUTFILE]
1