The following sections provide examples of how PROFOPTS might be used to tailor the environment to specific tasks.
If you do not want to profile a particular run,
you can set PROFOPTS to the null string
when you execute the profiled program:
$ PROFOPTS="" travel
Because you did not export PROFOPTS, this value will remain in effect for only one execution of the program. If you want to turn off profiling for more than one program and/or run, export the value of PROFOPTS:
$ PROFOPTS="" export PROFOPTS $ travelExporting the variable eliminates the need to specify it every time you execute travel. It also makes the value of PROFOPTS applicable to all runs of any profiled program, not just travel. Once you have exported PROFOPTS, it keeps the value you have given it until you unset or redefine the variable.
Suppose you are not interested in the data from a single run; you want the information collected from all runs. A data file that contains information from multiple executions is called a merged data file. When data files are merged, the line execution counts for all runs are added together.
The following screen shows how you must specify the environment if you want your data files from successive runs to be merged:
$ PROFOPTS="merge=y" export PROFOPTS $ travelAs noted, the merge will fail if the program has been recompiled between runs; the data file associated with the second run will be stored in TMPDIR, and its path name will be printed to stderr. See ``Invoking lprof'' for command line options to lprof that enable you to merge existing data files of a recompiled program.
INFO: Dumping profiling data from process 'travel' . . . INFO: CNTFILE `travel.cnt' created
INFO: Dumping profiling data from process 'travel' . . . INFO: CNTFILE `travel.cnt' updated
To avoid clutter in your current directory,
you may want to create a directory
specifically for data files.
When you assign that directory to the PROFOPTS
environment variable, your data files will be
created in that directory:
$ PROFOPTS="dir=cntfiles" travel
In this case, travel.cnt will be created in the directory cntfiles.
You may want to write a shell script that runs a profiled program automatically. That could be useful for tasks you perform frequently, such as determining test coverage. In that case,
You can specify these conditions
in PROFOPTS as follows:
$ PROFOPTS="msg=n,merge=y,file=test1.cnt" prog < test1
In this example, the profiling data will be written to a merged data file with the name test1.cnt rather than the default name prog.cnt.
If a profiled program uses the system call fork(2), the data files of both the parent and child processes will have the same name by default. You can avoid that by using the PROFOPTS option pid. By setting pid to y, you insure 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.
What happens when you run a program that forks without using the pid option? If you have set merge=y, the data will be merged; data from separate processes will be indistinguishable. If you have set merge=n, the last process to dump data will overwrite the data file.
The following screen shows how the pid option works, where forkprog is a program that uses fork:
$ PROFOPTS="pid=y" forkprog
INFO: Dumping profiling data from process `forkprog' . . . INFO: CNTFILE `922.forkprog.cnt' created
INFO: Dumping profiling data from process `forkprog' . . . INFO: CNTFILE `923.forkprog.cnt' created