Gprof Tutorial

From HPC Wiki
Jump to navigation Jump to search

This tutorial deals with the topic of applications performance analysis with the GNU profiler Gprof. Profiling applications gives valuable insights into the program structure and exposes performance bottlenecks, which point to sections of the code where optimizations are most effective.

The tutorial covers all necessary basics to get started with Gprof: it shows how to instrument applications, how to generate performance information for an application run and how to evaluate the results. In addition, it explains how to visualize the application structure using call graphs and how to annotate the application's source code with runtime information. Three real-world examples from the areas of biology, computer science and mechanical engineering demonstrate that this works with different programming languages (C/C++, Fortran), different compilers (GNU, Intel) and even parallel applications (threads, MPI).


( Slides as pdf)

Quiz

1. What languages can Gprof profile?

Python, Java, Julia
C/C++, Fortran, Pascal
Haskell, Cobol, Whitespace

2. How does Gprof generate a performance profile of an application?

By instrumenting the application during compilation.
Through static analysis of the source code
By means of hardware performance counters.

3. What compiler/linker flag is used to instrument the application?

-pg
-pig
--profile

4. Which compiler(s) support(s) Gprof?

only commercial compilers (e.g., from Intel)
only open-source compilers (e.g., from GNU)
many different compilers (e.g., from GNU and Intel)

4. How should the input parameters be when running the instrumented application?

Simple and understandable
Representative of the usual workload
Covering edge cases

5. What is a call graph?

An android app to show incoming callers
A hierarchy diagram of function calls in a given profile
Instructions of how to call for help during emergencies

6. How do you generate a call graph of a Gprof profile?

gprof --call-graph
gprof-call-graph
gprof --graph

7. What is gprof2dot?

Third party script for call graph visualization via the "dot" library
Gprof feature to export profiles as a pdf
A fork of the beta version of Gprof2

8. Does Gprof work with parallel applications?

No, Gprof only works with sequential applications
Yes, but Gprof cannot differentiate between individual threads or processes
Yes, parallel profiling is the main use-case of Gprof

9. How much runtime overhead does Gprof produce?

None
Little
Much