Go to the first, previous, next, last section, table of contents.

Executing the Program to Generate Profile Data

Once the program is compiled for profiling, you must run it in order to generate the information that gprof needs. Simply run the program as usual, using the normal arguments, file names, etc. The program should run normally, producing the same output as usual. It will, however, run somewhat slower than normal because of the time spent collecting and the writing the profile data.

The way you run the program--the arguments and input that you give it--may have a dramatic effect on what the profile information shows. The profile data will describe the parts of the program that were activated for the particular input you use. For example, if the first command you give to your program is to quit, the profile data will show the time used in initialization and in cleanup, but not much else.

You program will write the profile data into a file called `gmon.out' just before exiting. If there is already a file called `gmon.out', its contents are overwritten. There is currently no way to tell the program to write the profile data under a different name, but you can rename the file afterward if you are concerned that it may be overwritten.

In order to write the `gmon.out' file properly, your program must exit normally: by returning from main or by calling exit. Calling the low-level function _exit does not write the profile data, and neither does abnormal termination due to an unhandled signal.

The `gmon.out' file is written in the program's current working directory at the time it exits. This means that if your program calls chdir, the `gmon.out' file will be left in the last directory your program chdir'd to. If you don't have permission to write in this directory, the file is not written. You may get a confusing error message if this happens. (We have not yet replaced the part of Unix responsible for this; when we do, we will make the error message comprehensible.)

Go to the first, previous, next, last section, table of contents.