HP C Programmer's Guide (92434-90009)

Chapter 4 69
Optimizing HP C Programs
Profile-Based Optimization
Collecting Data for Profiling
To collect execution profile statistics, run your
instrumented
program with representative
data as follows:
sample.exe < input.file1
Collect execution profile data.
sample.exe < input.file2
This step creates and logs the profile statistics to a file, by default called flow.data. The
data collection file is a structured file that may be used to store the statistics from multiple
test runs of different programs that you may have instrumented.
Performing Profile-Based Optimization
To optimize the program based on the previously collected run-time profile statistics,
relink the program as follows:
cc -o sample.exe +P -O sample.o
An alternative to this procedure is to recompile the source file in the optimization step:
cc -o sample.exe +I -0 sample.c
instrumentation
sample.exe < input.file1
data collection
cc -o sample.exe +P -O sample.c
optimization
Maintaining Profile Data Files
Profile-based optimization stores execution profile data in a disk file. By default, this file is
called flow.data and is located in your current working directory.
You can override the default name of the profile data file. This is useful when working on
large programs or on projects with many different program files.
The FLOW_DATA environment variable can be used to specify the name of the profile data
file with either the +I or +P options. The +df command line option can be used to specify
the name of the profile data file when used with the +P option.
The +df option takes precedence over the FLOW_DATA environment variable.
In the following example, the FLOW_DATA environment variable is used to override the
flow.data file name. The profile data is stored instead in /users/profiles/prog.data.
%setenv FLOW_DATA /users/profiles/prog.data
%cc -Aa -c +I +O3 sample.c
%cc -o sample.exe +I +03 sample.o
%sample.exe < input.file1
%cc -o sample.exe +P +03 sample.o
In the next example, the +df option is used to override the flow.data file name with the
name /users/profiles/prog.data.
%cc -Aa -c +I +O3 sample.c