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
5Copyright (C) 1988-2021 Free Software Foundation, Inc.
6
7Permission is granted to copy, distribute and/or modify this document
8under the terms of the GNU Free Documentation License, Version 1.3
9or any later version published by the Free Software Foundation;
10with no Invariant Sections, with no Front-Cover Texts, and with no
11Back-Cover Texts.  A copy of the license is included in the
12section entitled "GNU Free Documentation License".
13 -->
14<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
15<head>
16<title>GNU gprof: Executing</title>
17
18<meta name="description" content="GNU gprof: Executing">
19<meta name="keywords" content="GNU gprof: Executing">
20<meta name="resource-type" content="document">
21<meta name="distribution" content="global">
22<meta name="Generator" content="makeinfo">
23<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
24<link href="index.html#Top" rel="start" title="Top">
25<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
26<link href="index.html#Top" rel="up" title="Top">
27<link href="Invoking.html#Invoking" rel="next" title="Invoking">
28<link href="Compiling.html#Compiling" rel="previous" title="Compiling">
29<style type="text/css">
30<!--
31a.summary-letter {text-decoration: none}
32blockquote.smallquotation {font-size: smaller}
33div.display {margin-left: 3.2em}
34div.example {margin-left: 3.2em}
35div.indentedblock {margin-left: 3.2em}
36div.lisp {margin-left: 3.2em}
37div.smalldisplay {margin-left: 3.2em}
38div.smallexample {margin-left: 3.2em}
39div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
40div.smalllisp {margin-left: 3.2em}
41kbd {font-style:oblique}
42pre.display {font-family: inherit}
43pre.format {font-family: inherit}
44pre.menu-comment {font-family: serif}
45pre.menu-preformatted {font-family: serif}
46pre.smalldisplay {font-family: inherit; font-size: smaller}
47pre.smallexample {font-size: smaller}
48pre.smallformat {font-family: inherit; font-size: smaller}
49pre.smalllisp {font-size: smaller}
50span.nocodebreak {white-space:nowrap}
51span.nolinebreak {white-space:nowrap}
52span.roman {font-family:serif; font-weight:normal}
53span.sansserif {font-family:sans-serif; font-weight:normal}
54ul.no-bullet {list-style: none}
55-->
56</style>
57
58
59</head>
60
61<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
62<a name="Executing"></a>
63<div class="header">
64<p>
65Next: <a href="Invoking.html#Invoking" accesskey="n" rel="next">Invoking</a>, Previous: <a href="Compiling.html#Compiling" accesskey="p" rel="previous">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>
66</div>
67<hr>
68<a name="Executing-the-Program"></a>
69<h2 class="chapter">3 Executing the Program</h2>
70
71<p>Once the program is compiled for profiling, you must run it in order to
72generate the information that <code>gprof</code> needs.  Simply run the program
73as usual, using the normal arguments, file names, etc.  The program should
74run normally, producing the same output as usual.  It will, however, run
75somewhat slower than normal because of the time spent collecting and
76writing the profile data.
77</p>
78<p>The way you run the program&mdash;the arguments and input that you give
79it&mdash;may have a dramatic effect on what the profile information shows.  The
80profile data will describe the parts of the program that were activated for
81the particular input you use.  For example, if the first command you give
82to your program is to quit, the profile data will show the time used in
83initialization and in cleanup, but not much else.
84</p>
85<p>Your program will write the profile data into a file called <samp>gmon.out</samp>
86just before exiting.  If there is already a file called <samp>gmon.out</samp>,
87its contents are overwritten.  There is currently no way to tell the
88program to write the profile data under a different name, but you can rename
89the file afterwards if you are concerned that it may be overwritten.
90</p>
91<p>In order to write the <samp>gmon.out</samp> file properly, your program must exit
92normally: by returning from <code>main</code> or by calling <code>exit</code>.  Calling
93the low-level function <code>_exit</code> does not write the profile data, and
94neither does abnormal termination due to an unhandled signal.
95</p>
96<p>The <samp>gmon.out</samp> file is written in the program&rsquo;s <em>current working
97directory</em> at the time it exits.  This means that if your program calls
98<code>chdir</code>, the <samp>gmon.out</samp> file will be left in the last directory
99your program <code>chdir</code>&rsquo;d to.  If you don&rsquo;t have permission to write in
100this directory, the file is not written, and you will get an error message.
101</p>
102<p>Older versions of the <small>GNU</small> profiling library may also write a file
103called <samp>bb.out</samp>.  This file, if present, contains an human-readable
104listing of the basic-block execution counts.  Unfortunately, the
105appearance of a human-readable <samp>bb.out</samp> means the basic-block
106counts didn&rsquo;t get written into <samp>gmon.out</samp>.
107The Perl script <code>bbconv.pl</code>, included with the <code>gprof</code>
108source distribution, will convert a <samp>bb.out</samp> file into
109a format readable by <code>gprof</code>.  Invoke it like this:
110</p>
111<div class="smallexample">
112<pre class="smallexample">bbconv.pl &lt; bb.out &gt; <var>bh-data</var>
113</pre></div>
114
115<p>This translates the information in <samp>bb.out</samp> into a form that
116<code>gprof</code> can understand.  But you still need to tell <code>gprof</code>
117about the existence of this translated information.  To do that, include
118<var>bb-data</var> on the <code>gprof</code> command line, <em>along with
119<samp>gmon.out</samp></em>, like this:
120</p>
121<div class="smallexample">
122<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>]
123</pre></div>
124
125<hr>
126<div class="header">
127<p>
128Next: <a href="Invoking.html#Invoking" accesskey="n" rel="next">Invoking</a>, Previous: <a href="Compiling.html#Compiling" accesskey="p" rel="previous">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>
129</div>
130
131
132
133</body>
134</html>
135