Introduction.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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: Introduction</title>
  15. <meta name="description" content="GNU gprof: Introduction">
  16. <meta name="keywords" content="GNU gprof: Introduction">
  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="index.html#Top" rel="up" title="Top">
  24. <link href="Compiling.html#Compiling" rel="next" title="Compiling">
  25. <link href="index.html#Top" rel="prev" title="Top">
  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="Introduction"></a>
  57. <div class="header">
  58. <p>
  59. Next: <a href="Compiling.html#Compiling" accesskey="n" rel="next">Compiling</a>, Previous: <a href="index.html#Top" accesskey="p" rel="prev">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>
  60. </div>
  61. <hr>
  62. <a name="Introduction-to-Profiling"></a>
  63. <h2 class="chapter">1 Introduction to Profiling</h2>
  64. <p>Profiling allows you to learn where your program spent its time and which
  65. functions called which other functions while it was executing. This
  66. information can show you which pieces of your program are slower than you
  67. expected, and might be candidates for rewriting to make your program
  68. execute faster. It can also tell you which functions are being called more
  69. or less often than you expected. This may help you spot bugs that had
  70. otherwise been unnoticed.
  71. </p>
  72. <p>Since the profiler uses information collected during the actual execution
  73. of your program, it can be used on programs that are too large or too
  74. complex to analyze by reading the source. However, how your program is run
  75. will affect the information that shows up in the profile data. If you
  76. don&rsquo;t use some feature of your program while it is being profiled, no
  77. profile information will be generated for that feature.
  78. </p>
  79. <p>Profiling has several steps:
  80. </p>
  81. <ul>
  82. <li> You must compile and link your program with profiling enabled.
  83. See <a href="Compiling.html#Compiling">Compiling a Program for Profiling</a>.
  84. </li><li> You must execute your program to generate a profile data file.
  85. See <a href="Executing.html#Executing">Executing the Program</a>.
  86. </li><li> You must run <code>gprof</code> to analyze the profile data.
  87. See <a href="Invoking.html#Invoking"><code>gprof</code> Command Summary</a>.
  88. </li></ul>
  89. <p>The next three chapters explain these steps in greater detail.
  90. </p>
  91. <p>Several forms of output are available from the analysis.
  92. </p>
  93. <p>The <em>flat profile</em> shows how much time your program spent in each function,
  94. and how many times that function was called. If you simply want to know
  95. which functions burn most of the cycles, it is stated concisely here.
  96. See <a href="Flat-Profile.html#Flat-Profile">The Flat Profile</a>.
  97. </p>
  98. <p>The <em>call graph</em> shows, for each function, which functions called it, which
  99. other functions it called, and how many times. There is also an estimate
  100. of how much time was spent in the subroutines of each function. This can
  101. suggest places where you might try to eliminate function calls that use a
  102. lot of time. See <a href="Call-Graph.html#Call-Graph">The Call Graph</a>.
  103. </p>
  104. <p>The <em>annotated source</em> listing is a copy of the program&rsquo;s
  105. source code, labeled with the number of times each line of the
  106. program was executed. See <a href="Annotated-Source.html#Annotated-Source">The Annotated Source
  107. Listing</a>.
  108. </p>
  109. <p>To better understand how profiling works, you may wish to read
  110. a description of its implementation.
  111. See <a href="Implementation.html#Implementation">Implementation of Profiling</a>.
  112. </p>
  113. <hr>
  114. <div class="header">
  115. <p>
  116. Next: <a href="Compiling.html#Compiling" accesskey="n" rel="next">Compiling</a>, Previous: <a href="index.html#Top" accesskey="p" rel="prev">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>
  117. </div>
  118. </body>
  119. </html>