Gprof: Difference between revisions

112 bytes removed ,  4 years ago
no edit summary
No edit summary
No edit summary
Line 3: Line 3:
=GNU Profiler (gprof) = <!--T:1-->
=GNU Profiler (gprof) = <!--T:1-->
== What is gprof? ==
== What is gprof? ==
[https://sourceware.org/binutils/docs/gprof/ gprof] is a profiling software which collects information and statistics on your code. Generally, it searches for functions and subroutines in your program and insert timing instructions for each one. Then executing such modified program creates a raw data file which can be interpreted by gprof and turned into profiling statistics.
[https://sourceware.org/binutils/docs/gprof/ gprof] is a profiling software which collects information and compiles statistics on your code. Generally, it searches for functions and subroutines in your program and inserts timing instructions for each one. Executing such a modified program creates a raw data file which can be interpreted by gprof and turned into profiling statistics.


<!--T:2-->
<!--T:2-->
[https://sourceware.org/binutils/docs/gprof/ gprof] comes with the GNU compiler (such as GCC or GFORTRAN) and is available with the <tt>gcc</tt> module on Compute Canada clusters.
[https://sourceware.org/binutils/docs/gprof/ gprof] comes with the GNU compiler suite and is available with the <tt>gcc</tt> module on our clusters.


== Preparing your application == <!--T:3-->
== Preparing your application == <!--T:3-->
Line 14: Line 14:


=== Compiling your code === <!--T:4-->
=== Compiling your code === <!--T:4-->
To get useful information from [https://sourceware.org/binutils/docs/gprof/ gprof] , you first need to compile your code with debugging information enabled. With the GNU compilers, you do so by adding the <tt>-pg</tt> option during compilation. This option tells the compiler to generate extra code to write profile information suitable for the analysis. If it is not part of your compiler options then no call-graph data will be gathered. When you run gprof hoping to get the profiling data you may get the following error:
To get useful information from [https://sourceware.org/binutils/docs/gprof/ gprof], you first need to compile your code with debugging information enabled. With the GNU compilers, you do so by adding the <tt>-pg</tt> 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:
<pre>
<pre>
gprof: gmon.out file is missing call-graph data
gprof: gmon.out file is missing call-graph data
Line 21: Line 21:
Once your code has been compiled with the proper options, you then execute it:
Once your code has been compiled with the proper options, you then execute it:
{{Command|/path/to/your/executable arg1 arg2}}
{{Command|/path/to/your/executable arg1 arg2}}
You should run your code the same way as you would do it without gprof profiling; the execution line does not change.
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 <tt>gmon.out</tt> is created in the current working directory. Note that if your code changes the current directory, <tt>gmon.out</tt> will be created in the new working directory, insofar as your program has sufficient permissions for it to be created.  
Once the binary has been executed and finished without any errors, a new file <tt>gmon.out</tt> is created in the current working directory. Note that if your code changes the current directory, <tt>gmon.out</tt> will be created in the new working directory, insofar as your program has sufficient permissions to do so.  


=== Getting the profiling data === <!--T:5-->
=== Getting the profiling data === <!--T:5-->
rsnt_translations
56,563

edits