1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- This file documents the gprof profiler of the GNU system.
4
5Copyright (C) 1988-2021 Free Software Foundation, Inc.
6
7Permission is granted to copy, distribute and/or modify this document
8under the terms of the GNU Free Documentation License, Version 1.3
9or any later version published by the Free Software Foundation;
10with no Invariant Sections, with no Front-Cover Texts, and with no
11Back-Cover Texts.  A copy of the license is included in the
12section entitled "GNU Free Documentation License".
13 -->
14<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
15<head>
16<title>GNU gprof: Introduction</title>
17
18<meta name="description" content="GNU gprof: Introduction">
19<meta name="keywords" content="GNU gprof: Introduction">
20<meta name="resource-type" content="document">
21<meta name="distribution" content="global">
22<meta name="Generator" content="makeinfo">
23<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
24<link href="index.html#Top" rel="start" title="Top">
25<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
26<link href="index.html#Top" rel="up" title="Top">
27<link href="Compiling.html#Compiling" rel="next" title="Compiling">
28<link href="index.html#Top" rel="previous" title="Top">
29<style type="text/css">
30<!--
31a.summary-letter {text-decoration: none}
32blockquote.smallquotation {font-size: smaller}
33div.display {margin-left: 3.2em}
34div.example {margin-left: 3.2em}
35div.indentedblock {margin-left: 3.2em}
36div.lisp {margin-left: 3.2em}
37div.smalldisplay {margin-left: 3.2em}
38div.smallexample {margin-left: 3.2em}
39div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
40div.smalllisp {margin-left: 3.2em}
41kbd {font-style:oblique}
42pre.display {font-family: inherit}
43pre.format {font-family: inherit}
44pre.menu-comment {font-family: serif}
45pre.menu-preformatted {font-family: serif}
46pre.smalldisplay {font-family: inherit; font-size: smaller}
47pre.smallexample {font-size: smaller}
48pre.smallformat {font-family: inherit; font-size: smaller}
49pre.smalllisp {font-size: smaller}
50span.nocodebreak {white-space:nowrap}
51span.nolinebreak {white-space:nowrap}
52span.roman {font-family:serif; font-weight:normal}
53span.sansserif {font-family:sans-serif; font-weight:normal}
54ul.no-bullet {list-style: none}
55-->
56</style>
57
58
59</head>
60
61<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
62<a name="Introduction"></a>
63<div class="header">
64<p>
65Next: <a href="Compiling.html#Compiling" accesskey="n" rel="next">Compiling</a>, Previous: <a href="index.html#Top" accesskey="p" rel="previous">Top</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
66</div>
67<hr>
68<a name="Introduction-to-Profiling"></a>
69<h2 class="chapter">1 Introduction to Profiling</h2>
70
71
72<p>Profiling allows you to learn where your program spent its time and which
73functions called which other functions while it was executing.  This
74information can show you which pieces of your program are slower than you
75expected, and might be candidates for rewriting to make your program
76execute faster.  It can also tell you which functions are being called more
77or less often than you expected.  This may help you spot bugs that had
78otherwise been unnoticed.
79</p>
80<p>Since the profiler uses information collected during the actual execution
81of your program, it can be used on programs that are too large or too
82complex to analyze by reading the source.  However, how your program is run
83will affect the information that shows up in the profile data.  If you
84don&rsquo;t use some feature of your program while it is being profiled, no
85profile information will be generated for that feature.
86</p>
87<p>Profiling has several steps:
88</p>
89<ul>
90<li> You must compile and link your program with profiling enabled.
91See <a href="Compiling.html#Compiling">Compiling a Program for Profiling</a>.
92
93</li><li> You must execute your program to generate a profile data file.
94See <a href="Executing.html#Executing">Executing the Program</a>.
95
96</li><li> You must run <code>gprof</code> to analyze the profile data.
97See <a href="Invoking.html#Invoking"><code>gprof</code> Command Summary</a>.
98</li></ul>
99
100<p>The next three chapters explain these steps in greater detail.
101</p>
102
103<p>Several forms of output are available from the analysis.
104</p>
105<p>The <em>flat profile</em> shows how much time your program spent in each function,
106and how many times that function was called.  If you simply want to know
107which functions burn most of the cycles, it is stated concisely here.
108See <a href="Flat-Profile.html#Flat-Profile">The Flat Profile</a>.
109</p>
110<p>The <em>call graph</em> shows, for each function, which functions called it, which
111other functions it called, and how many times.  There is also an estimate
112of how much time was spent in the subroutines of each function.  This can
113suggest places where you might try to eliminate function calls that use a
114lot of time.  See <a href="Call-Graph.html#Call-Graph">The Call Graph</a>.
115</p>
116<p>The <em>annotated source</em> listing is a copy of the program&rsquo;s
117source code, labeled with the number of times each line of the
118program was executed.  See <a href="Annotated-Source.html#Annotated-Source">The Annotated Source
119Listing</a>.
120</p>
121<p>To better understand how profiling works, you may wish to read
122a description of its implementation.
123See <a href="Implementation.html#Implementation">Implementation of Profiling</a>.
124</p>
125<hr>
126<div class="header">
127<p>
128Next: <a href="Compiling.html#Compiling" accesskey="n" rel="next">Compiling</a>, Previous: <a href="index.html#Top" accesskey="p" rel="previous">Top</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
129</div>
130
131
132
133</body>
134</html>
135