You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Line_002dby_002dline.html 7.4KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>Line-by-line (GNU gprof)</title>
  16. <meta name="description" content="Line-by-line (GNU gprof)">
  17. <meta name="keywords" content="Line-by-line (GNU gprof)">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  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.indentedblock {margin-right: 0em}
  30. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  48. span.roman {font-family: initial; font-weight: normal}
  49. span.sansserif {font-family: sans-serif; font-weight: normal}
  50. ul.no-bullet {list-style: none}
  51. -->
  52. </style>
  53. </head>
  54. <body lang="en">
  55. <a name="Line_002dby_002dline"></a>
  56. <div class="header">
  57. <p>
  58. 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>
  59. </div>
  60. <hr>
  61. <a name="Line_002dby_002dline-Profiling"></a>
  62. <h3 class="section">5.3 Line-by-line Profiling</h3>
  63. <p><code>gprof</code>&rsquo;s &lsquo;<samp>-l</samp>&rsquo; option causes the program to perform
  64. <em>line-by-line</em> profiling. In this mode, histogram
  65. samples are assigned not to functions, but to individual
  66. lines of source code. This only works with programs compiled with
  67. older versions of the <code>gcc</code> compiler. Newer versions of <code>gcc</code>
  68. use a different program - <code>gcov</code> - to display line-by-line
  69. profiling information.
  70. </p>
  71. <p>With the older versions of <code>gcc</code> the program usually has to be
  72. compiled with a &lsquo;<samp>-g</samp>&rsquo; option, in addition to &lsquo;<samp>-pg</samp>&rsquo;, in order
  73. to generate debugging symbols for tracking source code lines.
  74. Note, in much older versions of <code>gcc</code> the program had to be
  75. compiled with the &lsquo;<samp>-a</samp>&rsquo; command-line option as well.
  76. </p>
  77. <p>The flat profile is the most useful output table
  78. in line-by-line mode.
  79. The call graph isn&rsquo;t as useful as normal, since
  80. the current version of <code>gprof</code> does not propagate
  81. call graph arcs from source code lines to the enclosing function.
  82. The call graph does, however, show each line of code
  83. that called each function, along with a count.
  84. </p>
  85. <p>Here is a section of <code>gprof</code>&rsquo;s output, without line-by-line profiling.
  86. Note that <code>ct_init</code> accounted for four histogram hits, and
  87. 13327 calls to <code>init_block</code>.
  88. </p>
  89. <div class="smallexample">
  90. <pre class="smallexample">Flat profile:
  91. Each sample counts as 0.01 seconds.
  92. % cumulative self self total
  93. time seconds seconds calls us/call us/call name
  94. 30.77 0.13 0.04 6335 6.31 6.31 ct_init
  95. Call graph (explanation follows)
  96. granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds
  97. index % time self children called name
  98. 0.00 0.00 1/13496 name_too_long
  99. 0.00 0.00 40/13496 deflate
  100. 0.00 0.00 128/13496 deflate_fast
  101. 0.00 0.00 13327/13496 ct_init
  102. [7] 0.0 0.00 0.00 13496 init_block
  103. </pre></div>
  104. <p>Now let&rsquo;s look at some of <code>gprof</code>&rsquo;s output from the same program run,
  105. this time with line-by-line profiling enabled. Note that <code>ct_init</code>&rsquo;s
  106. four histogram hits are broken down into four lines of source code&mdash;one hit
  107. occurred on each of lines 349, 351, 382 and 385. In the call graph,
  108. note how
  109. <code>ct_init</code>&rsquo;s 13327 calls to <code>init_block</code> are broken down
  110. into one call from line 396, 3071 calls from line 384, 3730 calls
  111. from line 385, and 6525 calls from 387.
  112. </p>
  113. <div class="smallexample">
  114. <pre class="smallexample">Flat profile:
  115. Each sample counts as 0.01 seconds.
  116. % cumulative self
  117. time seconds seconds calls name
  118. 7.69 0.10 0.01 ct_init (trees.c:349)
  119. 7.69 0.11 0.01 ct_init (trees.c:351)
  120. 7.69 0.12 0.01 ct_init (trees.c:382)
  121. 7.69 0.13 0.01 ct_init (trees.c:385)
  122. Call graph (explanation follows)
  123. granularity: each sample hit covers 4 byte(s) for 7.69% of 0.13 seconds
  124. % time self children called name
  125. 0.00 0.00 1/13496 name_too_long (gzip.c:1440)
  126. 0.00 0.00 1/13496 deflate (deflate.c:763)
  127. 0.00 0.00 1/13496 ct_init (trees.c:396)
  128. 0.00 0.00 2/13496 deflate (deflate.c:727)
  129. 0.00 0.00 4/13496 deflate (deflate.c:686)
  130. 0.00 0.00 5/13496 deflate (deflate.c:675)
  131. 0.00 0.00 12/13496 deflate (deflate.c:679)
  132. 0.00 0.00 16/13496 deflate (deflate.c:730)
  133. 0.00 0.00 128/13496 deflate_fast (deflate.c:654)
  134. 0.00 0.00 3071/13496 ct_init (trees.c:384)
  135. 0.00 0.00 3730/13496 ct_init (trees.c:385)
  136. 0.00 0.00 6525/13496 ct_init (trees.c:387)
  137. [6] 0.0 0.00 0.00 13496 init_block (trees.c:408)
  138. </pre></div>
  139. <hr>
  140. <div class="header">
  141. <p>
  142. 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>
  143. </div>
  144. </body>
  145. </html>