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