Open main menu

CDOT Wiki β

Changes

Profiling

456 bytes added, 10:33, 11 October 2019
Profiling Tools
These tools provide different combinations of profiling capabilities, and may provide additional functions.
=== An exampleExample: Profiling with 'gprof' ===
The <code>gprof</code> tool provides basic profiling capability using a combination of sampling (for times) and instrumentation (for call graph and counts). To use it:
# Build the software to be profiled using the <code>-pg</code> (profile generation) option to the gcc compiler. This may require that you modify the makefile or other build instructions, but it can often be done using the CFLAGS or CCOPTS variables passed to configure or make -- for example, <code>make ./configure CFLAGS="-g -pg -O2"</code>
# Execute the program. Ensure that you give it a typical to long execution time; if it is an interactive program, run through most of the commonly-used features, and if it is non-interactive, invoke it with common options and give it a good amount of data to process.
# Check that a file named <code>gmon.out</code> was produced when the program ran. If not, recheck the previous steps.
# display on the screen
gprof ''nameOfExecutable'' | gprof2dot | dot -Tps | displayTx11
 
=== Example: Profiling with perf ===
 
Perf does not use instrumentation, so no changes are required to the build process.
 
To record performance data, run perf with the <code>record</code> argument: <code>perf record '''nameOfExecutable''</code>
To display performance data, run perf with the <code>report</code> argument: <code>perf report|less</code for non-interactive output, or <code>perf report</code> for interactive display
{{Admon/note|Function vs. Method vs. Procedure|In procedural languages, called code blocks are often called '''functions'''. When programming in an object-oriented language, called code blocks may be called '''methods'''. Older or more general documentation may refer to called code blocks as '''procedures'''. The distinction between functions, methods, and procedures is effectively one of terminology and "packaging" only - at the [[Machine Language|machine code]] level, the distinction effectively disappears.}}