prof Command
Purpose
Displays object file profile data.
Syntax
Description
The prof command interprets profile data that is collected by the monitor subroutine for the object file Program (a.out by default). It reads the symbol table in the object file Program and correlates it with the profile file (mon.out by default). The prof command displays, for each external text symbol, the percentage of execution time spent between the address of that symbol and the address of the next, the number of times that function was called, and the average number of milliseconds per call.
To tally the number of calls to a function, you must have compiled the file by using the cc command with the -p flag. The -p flag causes the compiler to insert a call to the mcount subroutine into the object code generated for each recompiled function of your program. While the program runs, each time a parent calls a child function the child calls the mcount subroutine to increment a distinct counter for that parent-child pair. Programs that are not recompiled with the -p flag do not have the mcount subroutine that is inserted and therefore keep no record of which function called them.
The -p flag also arranges for the object file to include a special profiling startup function that calls the monitor subroutine when the program begins and ends. The call to the monitor subroutine when the program ends and writes the mon.out file. Therefore, only programs that explicitly exit or return from the main program cause the mon.out file to be produced.
PROF=filename:<filename>
for example, if you set
PROF=myprof
, then the generated file is named as
myprof.out
.The location and names of the objects loaded are stored in the mon.out file. If you do not select any flags, prof uses these names. Specify a program or use the -L option to access other objects.
glink
code that sets up the call to the actual routine.
If the timer clock goes off while running this code, time is charged
to a routine called routine.gl
, where routine is
the routine being called. For example, if the timer goes off while
in the glink
code to call the printf subroutine, time
is charged to the printf.gl routine.Flags
The mutually exclusive flags a, c, n, and t determine how the prof command sorts the output lines:
Item | Description |
---|---|
-a | Sorts by increasing the symbol address. |
-c | Sorts by decreasing the number of calls. |
-n | Sorts lexically by symbol name. |
-t | Sorts by decreasing percentage of total time (default). |
The mutually exclusive flags o and x specify how to display the address of each symbol monitored.
Item | Description |
---|---|
-o | Displays each address in octal, along with the symbol name. |
-x | Displays each address in hexadecimal, along with the symbol name. |
Use the following flags in any combination:
Item | Description |
---|---|
-g | Includes non-global symbols (static functions). |
-h | Suppresses the heading that is normally displayed on the report. This is useful if the report is to be processed further. |
-L PathName | Uses an alternative path name for locating shared objects. |
-m MonitorData | Takes profiling data from MonitorData instead of mon.out. |
-s | Produces a summary file in mon.sum. This is useful when more than one profile file is specified. |
-S | Displays a summary of monitoring parameters and statistics on standard error. |
-v | Suppresses all printing and sends a graphic version of the profile to standard output for display by the plot filters. So, when plotting, low, and high numbers, by default 0 and 100, can be given to cause a selected percentage of the profile to be plotted with higher resolution. |
-z | Includes all symbols in the profile range, even if associated with 0 (zero) calls and 0 (zero) time. |
Examples
- To display, without a header, the amount of time that is spent at each symbol address, which is
sorted by time, enter:
prof -t -h
- The following example obtains a local version of any shared library that is used to create the
runfile file in the /home/score/lib directory. The data
file that is used will be runfile.mon rather than mon.out.
prof -x -L/home/score/lib runfile -m runfile.mon
Files
Item | Description |
---|---|
mon.out | Default profile. |
a.out | Default object file. |
mon.sum | Summary profile. |