hc
2024-03-22 f63cd4c03ea42695d5f9b0e1798edd196923aae6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file documents the gprof profiler of the GNU system.
 
Copyright (C) 1988-2021 Free Software Foundation, Inc.
 
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, with no Front-Cover Texts, and with no
Back-Cover Texts.  A copy of the license is included in the
section entitled "GNU Free Documentation License".
 -->
<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU gprof: Line-by-line</title>
 
<meta name="description" content="GNU gprof: Line-by-line">
<meta name="keywords" content="GNU gprof: Line-by-line">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Output.html#Output" rel="up" title="Output">
<link href="Annotated-Source.html#Annotated-Source" rel="next" title="Annotated Source">
<link href="Cycles.html#Cycles" rel="previous" title="Cycles">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
 
 
</head>
 
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Line_002dby_002dline"></a>
<div class="header">
<p>
Next: <a href="Annotated-Source.html#Annotated-Source" accesskey="n" rel="next">Annotated Source</a>, Previous: <a href="Call-Graph.html#Call-Graph" accesskey="p" rel="previous">Call Graph</a>, Up: <a href="Output.html#Output" accesskey="u" rel="up">Output</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<hr>
<a name="Line_002dby_002dline-Profiling"></a>
<h3 class="section">5.3 Line-by-line Profiling</h3>
 
<p><code>gprof</code>&rsquo;s &lsquo;<samp>-l</samp>&rsquo; option causes the program to perform
<em>line-by-line</em> profiling.  In this mode, histogram
samples are assigned not to functions, but to individual
lines of source code.  This only works with programs compiled with
older versions of the <code>gcc</code> compiler.  Newer versions of <code>gcc</code>
use a different program - <code>gcov</code> - to display line-by-line
profiling information.
</p>
<p>With the older versions of <code>gcc</code> the program usually has to be
compiled with a &lsquo;<samp>-g</samp>&rsquo; option, in addition to &lsquo;<samp>-pg</samp>&rsquo;, in order
to generate debugging symbols for tracking source code lines.
Note, in much older versions of <code>gcc</code> the program had to be
compiled with the &lsquo;<samp>-a</samp>&rsquo; command-line option as well.
</p>
<p>The flat profile is the most useful output table
in line-by-line mode.
The call graph isn&rsquo;t as useful as normal, since
the current version of <code>gprof</code> does not propagate
call graph arcs from source code lines to the enclosing function.
The call graph does, however, show each line of code
that called each function, along with a count.
</p>
<p>Here is a section of <code>gprof</code>&rsquo;s output, without line-by-line profiling.
Note that <code>ct_init</code> accounted for four histogram hits, and
13327 calls to <code>init_block</code>.
</p>
<div class="smallexample">
<pre class="smallexample">Flat profile:
 
Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  us/call  us/call  name
 30.77      0.13     0.04     6335     6.31     6.31  ct_init
 
 
            Call graph (explanation follows)
 
 
granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds
 
index % time    self  children    called     name
 
                0.00    0.00       1/13496       name_too_long
                0.00    0.00      40/13496       deflate
                0.00    0.00     128/13496       deflate_fast
                0.00    0.00   13327/13496       ct_init
[7]      0.0    0.00    0.00   13496         init_block
 
</pre></div>
 
<p>Now let&rsquo;s look at some of <code>gprof</code>&rsquo;s output from the same program run,
this time with line-by-line profiling enabled.  Note that <code>ct_init</code>&rsquo;s
four histogram hits are broken down into four lines of source code&mdash;one hit
occurred on each of lines 349, 351, 382 and 385.  In the call graph,
note how
<code>ct_init</code>&rsquo;s 13327 calls to <code>init_block</code> are broken down
into one call from line 396, 3071 calls from line 384, 3730 calls
from line 385, and 6525 calls from 387.
</p>
<div class="smallexample">
<pre class="smallexample">Flat profile:
 
Each sample counts as 0.01 seconds.
  %   cumulative   self
 time   seconds   seconds    calls  name
  7.69      0.10     0.01           ct_init (trees.c:349)
  7.69      0.11     0.01           ct_init (trees.c:351)
  7.69      0.12     0.01           ct_init (trees.c:382)
  7.69      0.13     0.01           ct_init (trees.c:385)
 
 
            Call graph (explanation follows)
 
 
granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds
 
  % time    self  children    called     name
 
            0.00    0.00       1/13496       name_too_long (gzip.c:1440)
            0.00    0.00       1/13496       deflate (deflate.c:763)
            0.00    0.00       1/13496       ct_init (trees.c:396)
            0.00    0.00       2/13496       deflate (deflate.c:727)
            0.00    0.00       4/13496       deflate (deflate.c:686)
            0.00    0.00       5/13496       deflate (deflate.c:675)
            0.00    0.00      12/13496       deflate (deflate.c:679)
            0.00    0.00      16/13496       deflate (deflate.c:730)
            0.00    0.00     128/13496       deflate_fast (deflate.c:654)
            0.00    0.00    3071/13496       ct_init (trees.c:384)
            0.00    0.00    3730/13496       ct_init (trees.c:385)
            0.00    0.00    6525/13496       ct_init (trees.c:387)
[6]  0.0    0.00    0.00   13496         init_block (trees.c:408)
 
</pre></div>
 
 
<hr>
<div class="header">
<p>
Next: <a href="Annotated-Source.html#Annotated-Source" accesskey="n" rel="next">Annotated Source</a>, Previous: <a href="Call-Graph.html#Call-Graph" accesskey="p" rel="previous">Call Graph</a>, Up: <a href="Output.html#Output" accesskey="u" rel="up">Output</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
 
 
 
</body>
</html>