Difference between revisions of "Runtime profiling"

From HPC Wiki
Jump to navigation Jump to search
Line 6: Line 6:
 
== How to use gprof ==
 
== How to use gprof ==
  
 +
The first step is to compile and link the program with profiling enabled. For most compilers this is achieved by setting the ```-pg``` flag. For Intel compilers it is important to set the optimization flag afterward as the default optimization level is set to ```-O0``` when enabling profiling.
  
 +
Example for Intel tool chain:
 +
 +
```
 +
icc -pg -O3 -c  myfile1.c
 +
icc -pg -O3 -c  myfile2.c
 +
icc -o a.out -pg  myfile1.o myfile2.o
 +
```
  
 
== How to use perf ==
 
== How to use perf ==

Revision as of 14:40, 2 April 2019

Introduction

The initial task in any performance analysis is to figure out in which parts of the code the runtime is spent. One wants to focus for optimisation on those regions of the code to achieve an overall speedup of the code. The tool helping to get an overview of where the time is spent is called a runtime profiler. There exist two flavours: Instrumentation based and sampling based profilers. Instrumentation based profilers insert function calls to measure the time at points in the program. Additional tasks may be performed as e.g. determining the function call stack. While it is possible to insert instrumentation calls on the binary level the common way is that the compiler adds instrumentation functions. The standard tool in this area is gprof and almost any compiler supports to instrument the code for gprof. Statistical sampling based profiling on the other hand are based on probing of the programs call stack triggered by operating system interrupts at regular intervals. A widespread tool for sampling based profiling is the perf tool which builds on the builtin profiling infrastructure in recent Linux kernels. Both approaches have advantages and disadvantages: Instrumentation produces more accurate results but introduces more overhead and sampling has less overhead but produce less accurate results. Special care is necessary for runtime profiling of parallel (OpenMP or MPI) applications.

How to use gprof

The first step is to compile and link the program with profiling enabled. For most compilers this is achieved by setting the ```-pg``` flag. For Intel compilers it is important to set the optimization flag afterward as the default optimization level is set to ```-O0``` when enabling profiling.

Example for Intel tool chain:

``` icc -pg -O3 -c myfile1.c icc -pg -O3 -c myfile2.c icc -o a.out -pg myfile1.o myfile2.o ```

How to use perf