Profile an Application with Instrumentation
- Instrumentation compilation and linkingUse[Q]prof-gento produce an executable with instrumented information included. Use/Qcov-gen(Windows) option to obtain minimum instrumentation only for code coverage.Operating SystemCommandsLinux andmacOS*icpc -prof-gen -prof-dir/usr/profiled a1.cpp a2.cpp a3.cppicpc a1.o a2.o a3.oWindowsicl /Qprof-gen /Qprof-dirc:\profiled a1.cpp a2.cpp a3.cppicl a1.obj a2.obj a3.objWindowsicl /Qcov-gen /Qcov-dirc:/cov_data a1.cpp a2.cpp a3.cppicl a1.obj a2.obj a3.objUse the[Q]prof-diror/Qcov-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-gen=srcpos(Linux and) ormacOS*/Qprof-gen:srcpos(Windows) option; however, the extra information is collected to provide support for specific Intel tools, including the code coverage Tool. If you do not expect to use such tools, do not specify-prof-gen=srcpos(Linux and) ormacOS*/Qprof-gen:srcpos(Windows); the extended option does not provide better optimization and could slow parallel compile times. If you are interested in using the instrumentation only for code coverage, use the/Qcov-gen(Windows) option, instead of the/Qprof-gen:srcpos(Windows) option, to minimize instrumentation overhead.PGO data collection is optimized for collecting data on serial applications at the expense of some loss of precision on areas of high parallelism. However, you can specify thethreadsafekeyword with the-prof-gen(Linux* and) or themacOS*/Qprof-gen(Windows) compiler option for files or applications that contain parallel constructsusing OpenMP* features, for example. Using thethreadsafekeyword produces instrumented object files that support the collection of PGO data on applications that use a high level of parallelism but may increase the overhead for data collection.Unlike serial programs, parallel programsusing OpenMP*may involve dynamic scheduling of code paths, and counts collected may not be perfectly reproducible for the same training data set.
- Instrumented executionRun your instrumented program with a representative set of data to create one or more dynamic information files.Operating SystemCommandLinux andmacOS*./a1.outWindowsa1.exeExecuting the instrumented applications generates a 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.By default, the.dynfilename follows this naming convention:<timestamp>_<pid>.dyn. The.dynfile is either placed into a directory specified by an environment variable, a compile-time specified directory, or the current directory.To make it easy to distinguish files from different runs, you can specify a prefix for the.dynfilename in the environment variable,INTEL_PROF_DYN_PREFIX. In such a case, executing the instrumented application generates a.dynfilename as follows:<prefix>_<timestamp>_<pid>.dyn, where<prefix>is the identifier that you have specified. Be sure to set theINTEL_PROF_DYN_PREFIXenvironment variable prior to starting your instrumented application.The value specified inINTEL_PROF_DYN_PREFIXenvironment variable must not contain< > : " / \ | ? *characters. The default naming scheme will be used if an invalid prefix is specified.
- Feedback compilationBefore this step, copy all .dyn and .dpi files into the same directory. Compile and link the source files with[Q]prof-use; the option instructs the compiler to use the generated dynamic information to guide the optimization:Operating SystemExamplesLinux andmacOS*icpc -prof-use -ipo -prof-dir/usr/profiled a1.cpp a2.cpp a3.cppWindowsicl /Qprof-use /Qipo /Qprof-dir:c:\profiled a1.cpp a2.cpp a3.cppThis 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,O2, for phase 1, and specify more advanced optimizations,[Q]ipo, during the phase 3 (final) compilation. The example shown above usedO2in step 1 and[Q]ipoin step 3.