Profile an Application

Profiling an application includes the following three phases:

This topic provides detailed information on how to profile an application by providing sample commands for each of the three phases (or steps).

  1. Instrumentation compilation and linking

Use -prof-gen (Linux* and Mac OS*) or /Qprof-gen (Windows*) to produce an executable with instrumented information included.

Platform

Commands

Linux and Mac OS

icpc -prof-gen -prof-dir /profiled a1.cpp a2.cpp a3.cpp

icpc a1.o a2.o a3.o

Windows

icl /Qprof-gen /Qprof-dirc:\profiled a1.cpp a2.cpp a3.cpp

icl a1.obj a2.obj a3.obj

Use the -prof-dir (Linux and Mac OS) or /Qprof-dir (Windows) option if the application includes the source files located in multiple directories; using the option insures the profile information is generated in one consistent place. The example commands demonstrate how to combine these options on multiple sources.

The compiler gathers extra information when you use the -prof-genx (Linux and Mac OS) or /Qprof-genx (Windows) qualifier; however, the extra information is collected to provide support only for specific Intel tools, like the code-coverage tool. If you do not expect to use such tools, do not specify prof-genx; the extended option does not provide better optimization and could slow parallel compile times.

  1. Instrumented execution

Run your instrumented program with a representative set of data to create one or more dynamic information files.

Platform

Command

Linux and Mac OS

./a1.out

Windows

a1.exe

Executing the instrumented applications generates dynamic information file that has a unique name and .dyn suffix. A new dynamic information file is created every time you execute the instrumented program.

You can run the program more than once with different input data.

  1. Feedback compilation

Compile and link the source files with -prof-use (Linux and Mac OS) or /Qprof-use (Windows); the option instructs the compiler to use the generated dynamic information to guide the optimization:

Platform

Examples

Linux and Mac OS

icpc -prof-use -prof-dir/usr/profiled a1.cpp a2.cpp a3.cpp

Windows

icl /Qprof-use /Qprof-dirc:\profiled a1.cpp a2.cpp a3.cpp

This final phase compiles and links the sources files using the data from the dynamic information files generated during instrumented execution (phase 2).

In addition to the optimized executable, the compiler produces a pgopti.dpi file.

Most of the time, you should specify the default optimizations, -02 (Linux and Mac OS) or /O2 (Windows), for phase 1, and specify more advanced optimizations, -ipo (Linux) or /Qipo (Windows), during the final compilation. For example, the example shown above used -O2 (Linux) or /O2 (Windows) in step 1 and -ipo (Linux) or /Qipo (Windows) in step 3.

Note

The compiler ignores the -ipo (Linux and Mac OS) or /Qipo (Windows) option with -prof-gen (Linux and Mac OS) or /Qprof-gen (Windows).