Using profile-directed feedback
You can use profile-directed feedback (PDF) to tune the performance of
your application for a typical usage scenario. The compiler optimizes the
application based on an analysis of how often branches are taken and blocks
of code are executed. The PDF process is intended to be used
after other debugging and tuning is finished, as one of the last steps before
putting the application into production.
The following diagram illustrates the PDF process.
Figure 2. Profile-directed feedback
You first compile the program with the -qpdf1 option (with a minimum optimization level of -O), which generates profile data by using the
compiled program in the same ways that users will typically use it. You then
compile the program again, with the -qpdf2 option.
This optimizes the program based on the profile data, by invoking -qipa=level=0. Alternatively,
if you want to save considerable time by avoiding a full re-compilation in
the -qpdf2 step, you can simply re-link the object
files produced by the -qpdf1 step.
Note that you do not need to compile all of the application's code with
the -qpdf1 option to benefit from the PDF process;
in a large application, you might want to concentrate on those areas of the
code that can benefit most from optimization.
To use the -qpdf options:
- Compile some or all of the source files in the application with -qpdf1 and a minimum of -O. If you want to avoid full re-compilation in the -qpdf2 step, first compile with -qpdf1 but with
no linking, so that the object files are saved. Then link the object files
into an executable. To use this procedure, issue commands similar to the following
example:
xlc -c -qpdf1 -O file1.c file2.c
xlc -qpdf1 -O file1.o file2.o
- Run the application using a typical data set or several
typical data sets. It is important to use data that is representative of the
data that will be used by your application in a real-world scenario. When
the application exits, it writes profiling information to the PDF file in
the current working directory or the directory specified by the PDFDIR environment
variable.
- Re-compile the application with -qpdf2 and a minimum of -O. Alternatively, if you
saved the object files in step 1, you can simply re-link the object files;
for example, issue the following command:
xlc -qpdf2 -O file1.o file2.o
You can take more control of the PDF file generation, as follows:
- Compile some or all of the source files in the application with -qpdf1 and a minimum of -O.
- Run the application using a typical data set or several typical data sets.
This produces a PDF file in the current directory.
- Change the directory specified by the PDFDIR environment
variable to produce a PDF file in a different directory.
- Re-compile or re-link the application with -qpdf1 and a minimum of -O.
- Repeat steps 3 and 4 as often as you want.
- Use the mergepdf utility to combine the PDF
files into one PDF file. For example, if you produce three PDF files that
represent usage patterns that will occur 53%, 32%, and 15% of the time respectively,
you can use this command:
mergepdf -r 53 path1 -r 32 path2 -r 15 path3
- Re-compile or or re-link the application with -qpdf2 and a minimum of -O.
To collect more detailed information on function call and block statistics,
do the following:
- Compile the application with -qpdf1 -qshowpdf -O.
- Run the application using a typical data set or several typical data sets.
The application writes more detailed profiling information in the PDF file.
- Use the showpdf utility to view the information
in the PDF file.
To erase the information in the PDF directory, use the cleanpdf utility or the resetpdf utility.