|
|
The following
examples show how PROFOPTS can be used
to configure the environment
in typical profiling situations.
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.outHowever, 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.outExporting 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.
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
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" travelAll the data files will be created in the subdirectory cntfiles.
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:
PROFOPTS="msg=n, merge=y, file=test1.cnt" myprog < test1
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" forkprogdumping profiling data from process 'forkprog' . . . CNTFILE '922.forkprog.cnt' created
dumping profiling data from process 'forkprog' . . . CNTFILE '923.forkprog.cnt' created