HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)

Profile-based optimization benefits most applications, especially large applications
with multiple compilation units, such as compilers, editors, database managers, and
user interface managers.
Profile-based optimization should be enabled during the final stages of application
development. To obtain the best performance, reprofile and reoptimize your
application after making source code changes.
These steps are involved in performing profile-based optimization:
1. Instrumentation
2. Collecting Data for Profiling
3. Maintaining Profile Data Files
4. Performing Profile-Based Optimization
Instrumentation
To instrument your program, use the +Oprofile=collect option as follows:
aCC +Oprofile=collect -O -c sample.C
aCC +Oprofile=collect -O -o sample.exe sample.o
The first command line uses the +Oprofile=collect option to prepare the code for
instrumentation. The -c option in the first command line suppresses linking and creates
an object file called sample.o.
The second command line uses the -o option to link sample.o into sample.exe. The
+Oprofile=collect option instruments sample.exe with data collection code.
NOTE: Instrumented programs run slower than non-instrumented programs. Only use
instrumented code to collect statistics for 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
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.
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.
198 Optimizing HP aC++ Programs