How to Profile an application (using google-perftools)
(3 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
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". | 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 | + | The following instructions must be adapted 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) | + | 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/libtcmalloc.so:/usr/lib/libprofiler.so | export LD_PRELOAD=/usr/lib/libtcmalloc.so:/usr/lib/libprofiler.so | ||
Line 12: | Line 12: | ||
Secondarily we shall activate the profiler instructing on where to dump the data and which file shall be run. | 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: | For example if we want to write the profiling data in "/tmp/cavity_prof" we shall write: | ||
Line 19: | Line 19: | ||
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. | 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 | + | PDF output can be obtained by typing: |
google-pprof --pdf /usr/bin/python /tmp/cavity_prof > profiling_output.pdf (or "pprof --pdf /usr/bin/python /tmp/cavity_prof > profiling_output.pdf") | google-pprof --pdf /usr/bin/python /tmp/cavity_prof > profiling_output.pdf (or "pprof --pdf /usr/bin/python /tmp/cavity_prof > profiling_output.pdf") | ||
Line 26: | Line 26: | ||
− | Similarly text output | + | Similarly, text output can be obtained by typing: |
google-pprof --text /usr/bin/python /tmp/cavity_prof > profiling_output.txt (or "pprof --text /usr/bin/python /tmp/cavity_prof > profiling_output.txt") | google-pprof --text /usr/bin/python /tmp/cavity_prof > profiling_output.txt (or "pprof --text /usr/bin/python /tmp/cavity_prof > profiling_output.txt") | ||
+ | |||
+ | |||
+ | The file "/tmp/cavity_prof" can also be analyzed with some specific graphical interfaces like "kcachegrind". To prepare de data for kcachegrind type: | ||
+ | |||
+ | google-pprof --callgrind /usr/bin/python /tmp/cavity_prof > profiling_kcachegrind.txt (or "pprof --callgrind /usr/bin/python /tmp/cavity_prof > profiling_kcachegrind.txt") | ||
+ | |||
+ | And to visualize the information use kcachegrind: | ||
+ | |||
+ | kcachegrind profiling_kcachegrind.txt & |
Latest revision as of 17:17, 22 March 2014
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 must be adapted 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/libtcmalloc.so:/usr/lib/libprofiler.so
(In OpenSuse, both are joined in one, so you can type "export LD_PRELOAD=/usr/lib64/libtcmalloc_and_profiler.so")
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 test_fractstep_cont_laplacian.py
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 typing:
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 can be obtained by typing:
google-pprof --text /usr/bin/python /tmp/cavity_prof > profiling_output.txt (or "pprof --text /usr/bin/python /tmp/cavity_prof > profiling_output.txt")
The file "/tmp/cavity_prof" can also be analyzed with some specific graphical interfaces like "kcachegrind". To prepare de data for kcachegrind type:
google-pprof --callgrind /usr/bin/python /tmp/cavity_prof > profiling_kcachegrind.txt (or "pprof --callgrind /usr/bin/python /tmp/cavity_prof > profiling_kcachegrind.txt")
And to visualize the information use kcachegrind:
kcachegrind profiling_kcachegrind.txt &