Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / module-profile.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="profile-limits.html" />
<link rel="prev" href="node453.html" />
<link rel="parent" href="profile.html" />
<link rel="next" href="profile-stats.html" />
<meta name='aesop' content='information' />
<title>10.5 Reference Manual</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="10.4 What Is Deterministic"
href="node453.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="10. The Python Profiler"
href="profile.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="10.5.1 The Stats Class"
href="profile-stats.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="node453.html">10.4 What Is Deterministic</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="profile.html">10. The Python Profiler</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="profile-stats.html">10.5.1 The Stats Class</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0012500000000000000000">
10.5 Reference Manual</A>
</H1>
<P>
<A NAME="module-profile"></A>
<P>
The primary entry point for the profiler is the global function
<tt class="function">profile.run()</tt>. It is typically used to create any profile
information. The reports are formatted and printed using methods of
the class <tt class="class">pstats.Stats</tt>. The following is a description of all
of these standard entry points and functions. For a more in-depth
view of some of the code, consider reading the later section on
Profiler Extensions, which includes discussion of how to derive
``better'' profilers from the classes presented, or reading the source
code for these modules.
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3108' xml:id='l2h-3108' class="function">run</tt></b>(</nobr></td>
<td><var>command</var><big>[</big><var>, filename</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
<P>
This function takes a single argument that has can be passed to the
<tt class="keyword">exec</tt> statement, and an optional file name. In all cases this
routine attempts to <tt class="keyword">exec</tt> its first argument, and gather profiling
statistics from the execution. If no file name is present, then this
function automatically prints a simple profiling report, sorted by the
standard name string (file/line/function-name) that is presented in
each line. The following is a typical output from such a call:
<P>
<div class="verbatim"><pre>
main()
2706 function calls (2004 primitive calls) in 4.504 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
2 0.006 0.003 0.953 0.477 pobject.py:75(save_objects)
43/3 0.533 0.012 0.749 0.250 pobject.py:99(evaluate)
...
</pre></div>
<P>
The first line indicates that this profile was generated by the call:
<BR><code>profile.run('main()')</code>, and hence the exec'ed string is
<code>'main()'</code>. The second line indicates that 2706 calls were
monitored. Of those calls, 2004 were <i class="dfn">primitive</i>. We define
<i class="dfn">primitive</i> to mean that the call was not induced via recursion.
The next line: <code>Ordered by: standard name</code>, indicates that
the text string in the far right column was used to sort the output.
The column headings include:
<P>
<DL>
<DT><STRONG>ncalls </STRONG></DT>
<DD>for the number of calls,
<P>
</DD>
<DT><STRONG>tottime </STRONG></DT>
<DD>for the total time spent in the given function (and excluding time
made in calls to sub-functions),
<P>
</DD>
<DT><STRONG>percall </STRONG></DT>
<DD>is the quotient of <code>tottime</code> divided by <code>ncalls</code>
<P>
</DD>
<DT><STRONG>cumtime </STRONG></DT>
<DD>is the total time spent in this and all subfunctions (from invocation
till exit). This figure is accurate <em>even</em> for recursive
functions.
<P>
</DD>
<DT><STRONG>percall </STRONG></DT>
<DD>is the quotient of <code>cumtime</code> divided by primitive calls
<P>
</DD>
<DT><STRONG>filename:lineno(function) </STRONG></DT>
<DD>provides the respective data of each function
<P>
</DD>
</DL>
<P>
When there are two numbers in the first column (for example,
"<tt class="samp">43/3</tt>"), then the latter is the number of primitive calls, and
the former is the actual number of calls. Note that when the function
does not recurse, these two values are the same, and only the single
figure is printed.
<P>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3109' xml:id='l2h-3109' class="function">runctx</tt></b>(</nobr></td>
<td><var>command, globals, locals</var><big>[</big><var>, filename</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
This function is similar to <tt class="function">profile.run()</tt>, with added
arguments to supply the globals and locals dictionaries for the
<var>command</var> string.
</dl>
<P>
Analysis of the profiler data is done using this class from the
<tt class="module">pstats</tt> module:
<P>
<a id='l2h-3111' xml:id='l2h-3111'></a>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-3110' xml:id='l2h-3110' class="class">Stats</tt></b>(</nobr></td>
<td><var>filename</var><big>[</big><var>, ...</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
This class constructor creates an instance of a ``statistics object''
from a <var>filename</var> (or set of filenames). <tt class="class">Stats</tt> objects are
manipulated by methods, in order to print useful reports.
<P>
The file selected by the above constructor must have been created by
the corresponding version of <tt class="module">profile</tt>. To be specific, there is
<em>no</em> file compatibility guaranteed with future versions of this
profiler, and there is no compatibility with files produced by other
profilers (such as the old system profiler).
<P>
If several files are provided, all the statistics for identical
functions will be coalesced, so that an overall view of several
processes can be considered in a single report. If additional files
need to be combined with data in an existing <tt class="class">Stats</tt> object, the
<tt class="method">add()</tt> method can be used.
</dl>
<P>
<p><br /></p><hr class='online-navigation' />
<div class='online-navigation'>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
<UL CLASS="ChildLinks">
<LI><A href="profile-stats.html">10.5.1 The <tt class="class">Stats</tt> Class</a>
</ul>
<!--End of Table of Child-Links-->
</div>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="10.4 What Is Deterministic"
href="node453.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="10. The Python Profiler"
href="profile.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="10.5.1 The Stats Class"
href="profile-stats.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="node453.html">10.4 What Is Deterministic</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="profile.html">10. The Python Profiler</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="profile-stats.html">10.5.1 The Stats Class</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>