blob: e4bd8c9e99502d36250a22e10744e0a4fbb04016 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file documents the gprof profiler of the GNU system.
Copyright (C) 1988, 1992, 1997, 1998, 1999, 2000, 2001, 2003,
2007, 2008, 2009 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, with no Front-Cover Texts, and with no
Back-Cover Texts. A copy of the license is included in the
section entitled "GNU Free Documentation License".
-->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU gprof: Executing</title>
<meta name="description" content="GNU gprof: Executing">
<meta name="keywords" content="GNU gprof: Executing">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="Invoking.html#Invoking" rel="next" title="Invoking">
<link href="Compiling.html#Compiling" rel="prev" title="Compiling">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Executing"></a>
<div class="header">
<p>
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>
</div>
<hr>
<a name="Executing-the-Program"></a>
<h2 class="chapter">3 Executing the Program</h2>
<p>Once the program is compiled for profiling, you must run it in order to
generate the information that <code>gprof</code> needs. Simply run the program
as usual, using the normal arguments, file names, etc. The program should
run normally, producing the same output as usual. It will, however, run
somewhat slower than normal because of the time spent collecting and
writing the profile data.
</p>
<p>The way you run the program&mdash;the arguments and input that you give
it&mdash;may have a dramatic effect on what the profile information shows. The
profile data will describe the parts of the program that were activated for
the particular input you use. For example, if the first command you give
to your program is to quit, the profile data will show the time used in
initialization and in cleanup, but not much else.
</p>
<p>Your program will write the profile data into a file called <samp>gmon.out</samp>
just before exiting. If there is already a file called <samp>gmon.out</samp>,
its contents are overwritten. There is currently no way to tell the
program to write the profile data under a different name, but you can rename
the file afterwards if you are concerned that it may be overwritten.
</p>
<p>In order to write the <samp>gmon.out</samp> file properly, your program must exit
normally: by returning from <code>main</code> or by calling <code>exit</code>. Calling
the low-level function <code>_exit</code> does not write the profile data, and
neither does abnormal termination due to an unhandled signal.
</p>
<p>The <samp>gmon.out</samp> file is written in the program&rsquo;s <em>current working
directory</em> at the time it exits. This means that if your program calls
<code>chdir</code>, the <samp>gmon.out</samp> file will be left in the last directory
your program <code>chdir</code>&rsquo;d to. If you don&rsquo;t have permission to write in
this directory, the file is not written, and you will get an error message.
</p>
<p>Older versions of the <small>GNU</small> profiling library may also write a file
called <samp>bb.out</samp>. This file, if present, contains an human-readable
listing of the basic-block execution counts. Unfortunately, the
appearance of a human-readable <samp>bb.out</samp> means the basic-block
counts didn&rsquo;t get written into <samp>gmon.out</samp>.
The Perl script <code>bbconv.pl</code>, included with the <code>gprof</code>
source distribution, will convert a <samp>bb.out</samp> file into
a format readable by <code>gprof</code>. Invoke it like this:
</p>
<div class="smallexample">
<pre class="smallexample">bbconv.pl &lt; bb.out &gt; <var>bh-data</var>
</pre></div>
<p>This translates the information in <samp>bb.out</samp> into a form that
<code>gprof</code> can understand. But you still need to tell <code>gprof</code>
about the existence of this translated information. To do that, include
<var>bb-data</var> on the <code>gprof</code> command line, <em>along with
<samp>gmon.out</samp></em>, like this:
</p>
<div class="smallexample">
<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>]
</pre></div>
<hr>
<div class="header">
<p>
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>
</div>
</body>
</html>