DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
C programmer's productivity tools

Examples of using PROFOPTS

The following examples show how PROFOPTS can be used to configure the environment in typical profiling situations.

Turning off profiling

If you do not want to profile a particular run, you can set PROFOPTS to the null string on the command line when you run a profiled version of a program:

   $ PROFOPTS="" a.out
However, this value will remain in effect for only one execution of one program.

If you want to turn off profiling for more than one program or run, you must export the value of PROFOPTS:

   $ PROFOPTS=""; export PROFOPTS
   $ a.out
Exporting the variable eliminates the need to specify it every time you run the program. Once you have exported PROFOPTS, it keeps the value you have given it until you unset or redefine that variable. This makes the value of PROFOPTS accessible to all runs of any profiled programs.

Merging data files

Information collected from multiple executions can be collected into a merged data file. When data files created with the lprof compiling option are merged, the execution counts for all files are added together.

The following example shows how to configure the environment if you want data files from successive runs to be merged:

   $ PROFOPTS="merge=y"
   $ export PROFOPTS
   $ travel
   

dumping profiling data from process 'travel' . . . CNTFILE 'travel.cnt' created

$ travel

dumping profiling data from process 'travel' . . . CNTFILE 'travel.cnt' updated

Keeping data files in a separate directory

To avoid cluttering current directory, you may want to create a separate directory for data files. This directory must be specified on PROFOPTS For example:

   $ PROFOPTS="dir=cntfiles" travel
All the data files will be created in the subdirectory cntfiles.

Profiling within a shell script

You may want to write a shell script to run profiled programs automatically. This facilitates specifying several PROFOPTS conditions for a particular program. The shell script in the next example implements the following conditions:

Here is the script:
   PROFOPTS="msg=n, merge=y, file=test1.cnt" myprog < test1

Profiling programs that fork

If a program uses the system call fork(S), the data files of the parent and child processes will have the same name by default. You can avoid this by using the PROFOPTS option pid. By setting pid=y, you ensure that the data file name will include the process ID of the program being profiled. As a result, multiple data files will be created, each with a unique name.

If you run a program that forks without setting pid=y option, then:

The following example shows how the pid option works. Notice names of the data files that are created (as reported by the messages sent to stderr):

   $ PROFOPTS="pid=y" forkprog
   

dumping profiling data from process 'forkprog' . . . CNTFILE '922.forkprog.cnt' created

dumping profiling data from process 'forkprog' . . . CNTFILE '923.forkprog.cnt' created


Next topic: Interpreting profiling output
Previous topic: The PROFOPTS environment variable

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003