Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > e1011ddec34cda34f3a002b121247943 > files > 798

python-docs-2.7.17-1.1.mga7.noarch.rpm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>26.5. hotshot — High performance logging profiler &#8212; Python 2.7.17 documentation</title>
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 2.7.17 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="next" title="26.6. timeit — Measure execution time of small code snippets" href="timeit.html" />
    <link rel="prev" title="26.4. The Python Profilers" href="profile.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/2/library/hotshot.html" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
 
    

  </head><body>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="timeit.html" title="26.6. timeit — Measure execution time of small code snippets"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="profile.html" title="26.4. The Python Profilers"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">Python 2.7.17 documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="debug.html" accesskey="U">26. Debugging and Profiling</a> &#187;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-hotshot">
<span id="hotshot-high-performance-logging-profiler"></span><h1>26.5. <a class="reference internal" href="#module-hotshot" title="hotshot: High performance logging profiler, mostly written in C."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hotshot</span></code></a> — High performance logging profiler<a class="headerlink" href="#module-hotshot" title="Permalink to this headline">¶</a></h1>
<div class="versionadded">
<p><span class="versionmodified added">New in version 2.2.</span></p>
</div>
<p>This module provides a nicer interface to the <code class="xref py py-mod docutils literal notranslate"><span class="pre">_hotshot</span></code> C module. Hotshot
is a replacement for the existing <a class="reference internal" href="profile.html#module-profile" title="profile: Python source profiler."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code></a> module. As it’s written mostly
in C, it should result in a much smaller performance impact than the existing
<a class="reference internal" href="profile.html#module-profile" title="profile: Python source profiler."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code></a> module.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The <a class="reference internal" href="#module-hotshot" title="hotshot: High performance logging profiler, mostly written in C."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hotshot</span></code></a> module focuses on minimizing the overhead while profiling, at
the expense of long data post-processing times. For common usage it is
recommended to use <a class="reference internal" href="profile.html#module-cProfile" title="cProfile"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cProfile</span></code></a> instead. <a class="reference internal" href="#module-hotshot" title="hotshot: High performance logging profiler, mostly written in C."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hotshot</span></code></a> is not maintained and
might be removed from the standard library in the future.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 2.5: </span>The results should be more meaningful than in the past: the timing core
contained a critical bug.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The <a class="reference internal" href="#module-hotshot" title="hotshot: High performance logging profiler, mostly written in C."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hotshot</span></code></a> profiler does not yet work well with threads. It is useful to
use an unthreaded script to run the profiler over the code you’re interested in
measuring if at all possible.</p>
</div>
<dl class="class">
<dt id="hotshot.Profile">
<em class="property">class </em><code class="descclassname">hotshot.</code><code class="descname">Profile</code><span class="sig-paren">(</span><em>logfile</em><span class="optional">[</span>, <em>lineevents</em><span class="optional">[</span>, <em>linetimings</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#hotshot.Profile" title="Permalink to this definition">¶</a></dt>
<dd><p>The profiler object. The argument <em>logfile</em> is the name of a log file to use for
logged profile data. The argument <em>lineevents</em> specifies whether to generate
events for every source line, or just on function call/return. It defaults to
<code class="docutils literal notranslate"><span class="pre">0</span></code> (only log function call/return). The argument <em>linetimings</em> specifies
whether to record timing information. It defaults to <code class="docutils literal notranslate"><span class="pre">1</span></code> (store timing
information).</p>
</dd></dl>

<div class="section" id="profile-objects">
<span id="hotshot-objects"></span><h2>26.5.1. Profile Objects<a class="headerlink" href="#profile-objects" title="Permalink to this headline">¶</a></h2>
<p>Profile objects have the following methods:</p>
<dl class="method">
<dt id="hotshot.Profile.addinfo">
<code class="descclassname">Profile.</code><code class="descname">addinfo</code><span class="sig-paren">(</span><em>key</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#hotshot.Profile.addinfo" title="Permalink to this definition">¶</a></dt>
<dd><p>Add an arbitrary labelled value to the profile output.</p>
</dd></dl>

<dl class="method">
<dt id="hotshot.Profile.close">
<code class="descclassname">Profile.</code><code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hotshot.Profile.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Close the logfile and terminate the profiler.</p>
</dd></dl>

<dl class="method">
<dt id="hotshot.Profile.fileno">
<code class="descclassname">Profile.</code><code class="descname">fileno</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hotshot.Profile.fileno" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the file descriptor of the profiler’s log file.</p>
</dd></dl>

<dl class="method">
<dt id="hotshot.Profile.run">
<code class="descclassname">Profile.</code><code class="descname">run</code><span class="sig-paren">(</span><em>cmd</em><span class="sig-paren">)</span><a class="headerlink" href="#hotshot.Profile.run" title="Permalink to this definition">¶</a></dt>
<dd><p>Profile an <a class="reference internal" href="../reference/simple_stmts.html#exec"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">exec</span></code></a>-compatible string in the script environment. The
globals from the <a class="reference internal" href="__main__.html#module-__main__" title="__main__: The environment where the top-level script is run."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module are used as both the globals and locals
for the script.</p>
</dd></dl>

<dl class="method">
<dt id="hotshot.Profile.runcall">
<code class="descclassname">Profile.</code><code class="descname">runcall</code><span class="sig-paren">(</span><em>func</em>, <em>*args</em>, <em>**keywords</em><span class="sig-paren">)</span><a class="headerlink" href="#hotshot.Profile.runcall" title="Permalink to this definition">¶</a></dt>
<dd><p>Profile a single call of a callable. Additional positional and keyword arguments
may be passed along; the result of the call is returned, and exceptions are
allowed to propagate cleanly, while ensuring that profiling is disabled on the
way out.</p>
</dd></dl>

<dl class="method">
<dt id="hotshot.Profile.runctx">
<code class="descclassname">Profile.</code><code class="descname">runctx</code><span class="sig-paren">(</span><em>cmd</em>, <em>globals</em>, <em>locals</em><span class="sig-paren">)</span><a class="headerlink" href="#hotshot.Profile.runctx" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluate an <a class="reference internal" href="../reference/simple_stmts.html#exec"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">exec</span></code></a>-compatible string in a specific environment. The
string is compiled before profiling begins.</p>
</dd></dl>

<dl class="method">
<dt id="hotshot.Profile.start">
<code class="descclassname">Profile.</code><code class="descname">start</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hotshot.Profile.start" title="Permalink to this definition">¶</a></dt>
<dd><p>Start the profiler.</p>
</dd></dl>

<dl class="method">
<dt id="hotshot.Profile.stop">
<code class="descclassname">Profile.</code><code class="descname">stop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hotshot.Profile.stop" title="Permalink to this definition">¶</a></dt>
<dd><p>Stop the profiler.</p>
</dd></dl>

</div>
<div class="section" id="module-hotshot.stats">
<span id="using-hotshot-data"></span><h2>26.5.2. Using hotshot data<a class="headerlink" href="#module-hotshot.stats" title="Permalink to this headline">¶</a></h2>
<div class="versionadded">
<p><span class="versionmodified added">New in version 2.2.</span></p>
</div>
<p>This module loads hotshot profiling data into the standard <a class="reference internal" href="profile.html#module-pstats" title="pstats: Statistics object for use with the profiler."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pstats</span></code></a> Stats
objects.</p>
<dl class="function">
<dt id="hotshot.stats.load">
<code class="descclassname">hotshot.stats.</code><code class="descname">load</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="headerlink" href="#hotshot.stats.load" title="Permalink to this definition">¶</a></dt>
<dd><p>Load hotshot data from <em>filename</em>. Returns an instance of the
<a class="reference internal" href="profile.html#pstats.Stats" title="pstats.Stats"><code class="xref py py-class docutils literal notranslate"><span class="pre">pstats.Stats</span></code></a> class.</p>
</dd></dl>

<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt>Module <a class="reference internal" href="profile.html#module-profile" title="profile: Python source profiler."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code></a></dt><dd><p>The <a class="reference internal" href="profile.html#module-profile" title="profile: Python source profiler."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code></a> module’s <code class="xref py py-class docutils literal notranslate"><span class="pre">Stats</span></code> class</p>
</dd>
</dl>
</div>
</div>
<div class="section" id="example-usage">
<span id="hotshot-example"></span><h2>26.5.3. Example Usage<a class="headerlink" href="#example-usage" title="Permalink to this headline">¶</a></h2>
<p>Note that this example runs the Python “benchmark” pystones.  It can take some
time to run, and will produce large output files.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">hotshot</span><span class="o">,</span> <span class="nn">hotshot.stats</span><span class="o">,</span> <span class="nn">test.pystone</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">prof</span> <span class="o">=</span> <span class="n">hotshot</span><span class="o">.</span><span class="n">Profile</span><span class="p">(</span><span class="s2">&quot;stones.prof&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">benchtime</span><span class="p">,</span> <span class="n">stones</span> <span class="o">=</span> <span class="n">prof</span><span class="o">.</span><span class="n">runcall</span><span class="p">(</span><span class="n">test</span><span class="o">.</span><span class="n">pystone</span><span class="o">.</span><span class="n">pystones</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">prof</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">stats</span> <span class="o">=</span> <span class="n">hotshot</span><span class="o">.</span><span class="n">stats</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="s2">&quot;stones.prof&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">stats</span><span class="o">.</span><span class="n">strip_dirs</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">stats</span><span class="o">.</span><span class="n">sort_stats</span><span class="p">(</span><span class="s1">&#39;time&#39;</span><span class="p">,</span> <span class="s1">&#39;calls&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">stats</span><span class="o">.</span><span class="n">print_stats</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="go">         850004 function calls in 10.090 CPU seconds</span>

<span class="go">   Ordered by: internal time, call count</span>

<span class="go">   ncalls  tottime  percall  cumtime  percall filename:lineno(function)</span>
<span class="go">        1    3.295    3.295   10.090   10.090 pystone.py:79(Proc0)</span>
<span class="go">   150000    1.315    0.000    1.315    0.000 pystone.py:203(Proc7)</span>
<span class="go">    50000    1.313    0.000    1.463    0.000 pystone.py:229(Func2)</span>
<span class="go"> .</span>
<span class="go"> .</span>
<span class="go"> .</span>
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">26.5. <code class="xref py py-mod docutils literal notranslate"><span class="pre">hotshot</span></code> — High performance logging profiler</a><ul>
<li><a class="reference internal" href="#profile-objects">26.5.1. Profile Objects</a></li>
<li><a class="reference internal" href="#module-hotshot.stats">26.5.2. Using hotshot data</a></li>
<li><a class="reference internal" href="#example-usage">26.5.3. Example Usage</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="profile.html"
                        title="previous chapter">26.4. The Python Profilers</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="timeit.html"
                        title="next chapter">26.6. <code class="xref py py-mod docutils literal notranslate"><span class="pre">timeit</span></code> — Measure execution time of small code snippets</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/library/hotshot.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="timeit.html" title="26.6. timeit — Measure execution time of small code snippets"
             >next</a> |</li>
        <li class="right" >
          <a href="profile.html" title="26.4. The Python Profilers"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">Python 2.7.17 documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="debug.html" >26. Debugging and Profiling</a> &#187;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2019, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Oct 19, 2019.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
    </div>

  </body>
</html>