Line_002dby_002dline.html 7.5 KB

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