Executing - GNU gprof
Description: GNU gprof

Next: Invoking, Previous: Compiling, Up: Top

## 3 Executing the Program

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 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.

Your 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 afterwards 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, and you will get an error message.

Older versions of the gnu profiling library may also write a file called `bb.out`. This file, if present, contains an human-readable listing of the basic-block execution counts. Unfortunately, the appearance of a human-readable `bb.out` means the basic-block counts didn't get written into `gmon.out`. The Perl script `bbconv.pl`, included with the `gprof` source distribution, will convert a `bb.out` file into a format readable by `gprof`. Invoke it like this:

         bbconv.pl < bb.out > bh-data

This translates the information in `bb.out` into a form that `gprof` can understand. But you still need to tell `gprof` about the existence of this translated information. To do that, include bb-data on the `gprof` command line, along with `gmon.out`, like this:

         gprof options executable-file gmon.out bb-data [yet-more-profile-data-files...] [> outfile]