Maximizing Performance with Profiling

The QNX Application Profiler lets you perform:

Sampling doesn't require instrumentation, and has low overhead, but your application needs to run for a long time for you to get sound data.

Sampling and Calls Count requires a compiler and linker flag, and has more overhead.

Function Instrumentation requires a compiler flag and linker flag, and even more overhead.

Statistical sample profiling (sampling)

The QNX Application Profiler takes a snapshot of your program's execution position every millisecond and records the current address being executed. By sampling the execution position at regular intervals, the profiling tool quickly builds a summary of where the system is spending its time in your code.

With statistical sample profiling, you don't need to use instrumentation, change your code, or to perform any special compilation. The profiling tool profiles your programs unobtrusively, which means that it doesn't bias the information it's collecting.

Note, however, that the results are subject to statistical inaccuracy because the profiling tool works by sampling. Therefore, the longer a program runs, the more accurate the results are.

Function Instrumentation profiling

This method provides you with precise function run time information for your project. It performs better on one thread, because with many threads, the overhead of such measurement can change the application's behavior.

To enable instrumentation, compile each source file with the option -finstrument-functions. This gcc option instructs the compiler to generate a call to the profiling function just after the entrance to, and just before the exit from every application function, which permits the collection of profiling information. Profiling functions are defined in the libprofilingS.a library; to access these, link the binary or library with the -lprofilingS option.

Note:

For an application that intends to use an instrumented library as a DLL (i.e. using a dlopen call), compile the library and the binary with the -Wl,-E linker option.

Sampling and Call Count instrumentation profiling

This type of profiling is a combination of sampling mode and Call Count instrumentation data, and it provides per line statistical coverage (as well as a call graph at the same time), with relatively small overhead.

To instrument a binary or library in this mode, use the -p option for both compiling and linking. The -p option for the compiler prepares the binary for profiling (the compiler will then insert code before each function to gather call information); however, it won't cause the profiling versions of the libraries to be linked in. To link in the profiling versions from the libc library, use the -p option for the linker.

If you compile and link with either the -pg or -p option, when the executable program runs, either gprof or prof monitors the program and produces a report file called gmon.out. The gprof utility can't report information about program calls to routines from a precompiled library (such as libc) that weren't compiled with the -pg option. Consequently, the resulting profiling information won't include data about calls made to those routines (for example printf).

If most of the execution time occurs in various library routines, then this fact will likely reduce the value of the profiling results, since there is no indication in the results of where the call was made. In this case, you can use Function Instrumentation profiling, which causes this additional time to be charged to the higher-level routine that called the library function.

Postmortem profiling for Call Count and Function Instrumentation profiling

The IDE lets you examine profiling information from an output file produced by an instrumented application (i.e. gmon.out). The tool provides you with all of the information collected at runtime, but in a graphical format.

Postmortem profiling supports data generated by gprof (gmon.out), the QNX profiler library (.ptrace), and the trace logger (.kev).

For more information about the gprof utility, go to www.gnu.org, see the Utilities Reference.