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.

134 line
6.3KB

  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>Executing (GNU gprof)</title>
  16. <meta name="description" content="Executing (GNU gprof)">
  17. <meta name="keywords" content="Executing (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="index.html#Top" rel="up" title="Top">
  24. <link href="Invoking.html#Invoking" rel="next" title="Invoking">
  25. <link href="Compiling.html#Compiling" rel="prev" title="Compiling">
  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="Executing"></a>
  56. <div class="header">
  57. <p>
  58. Next: <a href="Invoking.html#Invoking" accesskey="n" rel="next">Invoking</a>, Previous: <a href="Compiling.html#Compiling" accesskey="p" rel="prev">Compiling</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>
  59. </div>
  60. <hr>
  61. <a name="Executing-the-Program"></a>
  62. <h2 class="chapter">3 Executing the Program</h2>
  63. <p>Once the program is compiled for profiling, you must run it in order to
  64. generate the information that <code>gprof</code> needs. Simply run the program
  65. as usual, using the normal arguments, file names, etc. The program should
  66. run normally, producing the same output as usual. It will, however, run
  67. somewhat slower than normal because of the time spent collecting and
  68. writing the profile data.
  69. </p>
  70. <p>The way you run the program&mdash;the arguments and input that you give
  71. it&mdash;may have a dramatic effect on what the profile information shows. The
  72. profile data will describe the parts of the program that were activated for
  73. the particular input you use. For example, if the first command you give
  74. to your program is to quit, the profile data will show the time used in
  75. initialization and in cleanup, but not much else.
  76. </p>
  77. <p>Your program will write the profile data into a file called <samp>gmon.out</samp>
  78. just before exiting. If there is already a file called <samp>gmon.out</samp>,
  79. its contents are overwritten. There is currently no way to tell the
  80. program to write the profile data under a different name, but you can rename
  81. the file afterwards if you are concerned that it may be overwritten.
  82. </p>
  83. <p>In order to write the <samp>gmon.out</samp> file properly, your program must exit
  84. normally: by returning from <code>main</code> or by calling <code>exit</code>. Calling
  85. the low-level function <code>_exit</code> does not write the profile data, and
  86. neither does abnormal termination due to an unhandled signal.
  87. </p>
  88. <p>The <samp>gmon.out</samp> file is written in the program&rsquo;s <em>current working
  89. directory</em> at the time it exits. This means that if your program calls
  90. <code>chdir</code>, the <samp>gmon.out</samp> file will be left in the last directory
  91. your program <code>chdir</code>&rsquo;d to. If you don&rsquo;t have permission to write in
  92. this directory, the file is not written, and you will get an error message.
  93. </p>
  94. <p>Older versions of the <small>GNU</small> profiling library may also write a file
  95. called <samp>bb.out</samp>. This file, if present, contains an human-readable
  96. listing of the basic-block execution counts. Unfortunately, the
  97. appearance of a human-readable <samp>bb.out</samp> means the basic-block
  98. counts didn&rsquo;t get written into <samp>gmon.out</samp>.
  99. The Perl script <code>bbconv.pl</code>, included with the <code>gprof</code>
  100. source distribution, will convert a <samp>bb.out</samp> file into
  101. a format readable by <code>gprof</code>. Invoke it like this:
  102. </p>
  103. <div class="smallexample">
  104. <pre class="smallexample">bbconv.pl &lt; bb.out &gt; <var>bh-data</var>
  105. </pre></div>
  106. <p>This translates the information in <samp>bb.out</samp> into a form that
  107. <code>gprof</code> can understand. But you still need to tell <code>gprof</code>
  108. about the existence of this translated information. To do that, include
  109. <var>bb-data</var> on the <code>gprof</code> command line, <em>along with
  110. <samp>gmon.out</samp></em>, like this:
  111. </p>
  112. <div class="smallexample">
  113. <pre class="smallexample">gprof <var>options</var> <var>executable-file</var> gmon.out <var>bb-data</var> [<var>yet-more-profile-data-files</var>&hellip;] [&gt; <var>outfile</var>]
  114. </pre></div>
  115. <hr>
  116. <div class="header">
  117. <p>
  118. Next: <a href="Invoking.html#Invoking" accesskey="n" rel="next">Invoking</a>, Previous: <a href="Compiling.html#Compiling" accesskey="p" rel="prev">Compiling</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>
  119. </div>
  120. </body>
  121. </html>