home *** CD-ROM | disk | FTP | other *** search
- <TITLE>Reference Manual -- Python library reference</TITLE>
- Next: <A HREF="../l/limitations" TYPE="Next">Limitations</A>
- Prev: <A HREF="../d/deterministic_profiling" TYPE="Prev">Deterministic Profiling</A>
- Up: <A HREF="../t/the_python_profiler" TYPE="Up">The Python Profiler</A>
- Top: <A HREF="../t/top" TYPE="Top">Top</A>
- <H1>9.5. Reference Manual</H1>
- The primary entry point for the profiler is the global function
- <CODE>profile.run()</CODE>. It is typically used to create any profile
- information. The reports are formatted and printed using methods of
- the class <CODE>pstats.Stats</CODE>. 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><B>profile.run</B> (<VAR>string</VAR>[, <VAR>filename</VAR>[, ...]]) -- profiler function<DD>
- This function takes a single argument that has can be passed to the
- <CODE>exec</CODE> statement, and an optional file name. In all cases this
- routine attempts to <CODE>exec</CODE> 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>
- @small{
- <UL COMPACT><CODE> main()<P>
- 2706 function calls (2004 primitive calls) in 4.504 CPU seconds<P>
- <P>
- Ordered by: standard name<P>
- <P>
- ncalls tottime percall cumtime percall filename:lineno(function)<P>
- 2 0.006 0.003 0.953 0.477 pobject.py:75(save_objects)<P>
- 43/3 0.533 0.012 0.749 0.250 pobject.py:99(evaluate)<P>
- ...<P>
- </CODE></UL>
- }
- <P>
- The first line indicates that this profile was generated by the call:*
- <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 <DFN>primitive</DFN>. We define
- <DFN>primitive</DFN> 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><B>ncalls</B><DD>for the number of calls,
- <P>
- <DT><B>tottime</B><DD>for the total time spent in the given function (and excluding time
- made in calls to sub-functions),
- <P>
- <DT><B>percall</B><DD>is the quotient of <CODE>tottime</CODE> divided by <CODE>ncalls</CODE>
- <P>
- <DT><B>cumtime</B><DD>is the total time spent in this and all subfunctions (i.e., from
- invocation till exit). This figure is accurate <I>even</I> for recursive
- functions.
- <P>
- <DT><B>percall</B><DD>is the quotient of <CODE>cumtime</CODE> divided by primitive calls
- <P>
- <DT><B>filename:lineno(function)</B><DD>provides the respective data of each function
- <P>
- </DL>
- When there are two numbers in the first column (e.g.: `<SAMP>43/3</SAMP>'),
- 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>
- <DL><DT><B>pstats.Stats</B> (<VAR>filename</VAR>[, ...]) -- profiler function<DD>
- This class constructor creates an instance of a ``statistics object''
- from a <VAR>filename</VAR> (or set of filenames). <CODE>Stats</CODE> 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 <CODE>profile</CODE>. To be specific, there is
- <I>NO</I> file compatibility guaranteed with future versions of this
- profiler, and there is no compatibility with files produced by other
- profilers (e.g., 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 <CODE>Stats</CODE> object, the
- <CODE>add()</CODE> method can be used.
- </DL>
- <H2>Menu</H2><DL COMPACT>
- <DT><A HREF="../t/the_stats_class" TYPE=Menu>The Stats Class</A>
- <DD></DL>
-