How to Profile an application (using google-perftools)

From KratosWiki
Revision as of 13:56, 20 November 2013 by Maceli (Talk | contribs)
Jump to: navigation, search

Here we assume that the "google-perftools" are correctly installed in the system under the directory "/usr/lib". If your system is not Ubuntu (i.e. OpenSuse), the package can have a different name, like "gperftools", and you can find it installed in a different directory, like "/usr/lib64".

The following instructions shall be changed to reflect the actual installation directory for such libraries

Let's now imagine we wish to profile the "cavity2D" example of the "incompressible_fluid_application". We shall first of all preload the libraries needed (tcmalloc is NOT essential for this, althought it may be useful)

  export LD_PRELOAD=/usr/lib/

(In OpenSuse, both are joined in one, so you can type "export LD_PRELOAD=/usr/lib64/")

Secondarily we shall activate the profiler instructing on where to dump the data and which file shall be run. this is obtained by setting the environmental var CPUPROFILE followed by the run of the program. For example if we want to write the profiling data in "/tmp/cavity_prof" we shall write:

  CPUPROFILE=/tmp/cavity_prof python 

After this step the file "/tmp/cavity_prof" exists in the system. Such file need to be interpreted by the program "pprof" or "google-pprof" under ubuntu. PDF output can be obtained by

  google-pprof --pdf /usr/bin/python /tmp/cavity_prof > profiling_output.pdf       (or "pprof --pdf /usr/bin/python /tmp/cavity_prof > profiling_output.pdf")

which dumps the profiling output to the file named "profiling_output.pdf".

Similarly text output is obtained by

  google-pprof --text /usr/bin/python /tmp/cavity_prof > profiling_output.txt      (or "pprof --text /usr/bin/python /tmp/cavity_prof > profiling_output.txt")
Personal tools