gprof

From Alliance Doc
Revision as of 15:25, 8 October 2020 by Diane27 (talk | contribs) (Created page with "== Préparation du code == === Charger le compilateur === Chargez le compilateur GNU approprié; par exemple pour GCC la commande est {{Command|module load gcc/7.3.0}}")
Jump to navigation Jump to search
Other languages:

Profileur GNU gprof

Description

gprof est une application de profilage qui collecte de l’information et compile des statistiques sur votre code. De façon générale, gprof trouve les fonctions et les sous-routines dans le programme et y insère des temps de calcul pour chacune. Quand le programme est exécuté, un fichier de données brutes est créé et interprété par gprof qui en tire des statistiques de profilage.

gprof est fourni avec la suite GNU et est disponible via le module gcc.

Préparation du code

Charger le compilateur

Chargez le compilateur GNU approprié; par exemple pour GCC la commande est

Question.png
[name@server ~]$ module load gcc/7.3.0

Compiling your code

To get useful information from gprof, you first need to compile your code with debugging information enabled. With the GNU compilers, you do so by adding the -pg option to the compilation command. This option tells the compiler to generate extra code to write profile information suitable for the analysis. Without this option, no call-graph data will be gathered and you may get the following error:

gprof: gmon.out file is missing call-graph data

Executing your code

Once your code has been compiled with the proper options, you then execute it:

Question.png
[name@server ~]$ /path/to/your/executable arg1 arg2

You should run your code the same way as you would without gprof profiling; the execution line does not change. Once the binary has been executed and finished without any errors, a new file gmon.out is created in the current working directory. Note that if your code changes the current directory, gmon.out will be created in the new working directory, insofar as your program has sufficient permissions to do so.

Getting the profiling data

In this step the gprof tool is executed again with the binary name and the above mentioned gmon.out as argument; the analysis file is created with all the desired profiling information.

Question.png
[name@server ~]$ gprof /path/to/your/executable gmon.out > analysis.txt