~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-2.7.11-docs-html/library/hotshot.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
 
 
4
 
 
5
 
<html xmlns="http://www.w3.org/1999/xhtml">
6
 
  <head>
7
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
 
    
9
 
    <title>26.5. hotshot — High performance logging profiler &mdash; Python 2.7.11 documentation</title>
10
 
    
11
 
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
12
 
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13
 
    
14
 
    <script type="text/javascript">
15
 
      var DOCUMENTATION_OPTIONS = {
16
 
        URL_ROOT:    '../',
17
 
        VERSION:     '2.7.11',
18
 
        COLLAPSE_INDEX: false,
19
 
        FILE_SUFFIX: '.html',
20
 
        HAS_SOURCE:  true
21
 
      };
22
 
    </script>
23
 
    <script type="text/javascript" src="../_static/jquery.js"></script>
24
 
    <script type="text/javascript" src="../_static/underscore.js"></script>
25
 
    <script type="text/javascript" src="../_static/doctools.js"></script>
26
 
    <script type="text/javascript" src="../_static/sidebar.js"></script>
27
 
    <link rel="search" type="application/opensearchdescription+xml"
28
 
          title="Search within Python 2.7.11 documentation"
29
 
          href="../_static/opensearch.xml"/>
30
 
    <link rel="author" title="About these documents" href="../about.html" />
31
 
    <link rel="copyright" title="Copyright" href="../copyright.html" />
32
 
    <link rel="top" title="Python 2.7.11 documentation" href="../contents.html" />
33
 
    <link rel="up" title="26. Debugging and Profiling" href="debug.html" />
34
 
    <link rel="next" title="26.6. timeit — Measure execution time of small code snippets" href="timeit.html" />
35
 
    <link rel="prev" title="26.4. The Python Profilers" href="profile.html" />
36
 
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
 
    <script type="text/javascript" src="../_static/copybutton.js"></script>
38
 
    <script type="text/javascript" src="../_static/version_switch.js"></script>
39
 
 
40
 
    
41
 
 
42
 
  </head>
43
 
  <body role="document">  
44
 
    <div class="related" role="navigation" aria-label="related navigation">
45
 
      <h3>Navigation</h3>
46
 
      <ul>
47
 
        <li class="right" style="margin-right: 10px">
48
 
          <a href="../genindex.html" title="General Index"
49
 
             accesskey="I">index</a></li>
50
 
        <li class="right" >
51
 
          <a href="../py-modindex.html" title="Python Module Index"
52
 
             >modules</a> |</li>
53
 
        <li class="right" >
54
 
          <a href="timeit.html" title="26.6. timeit — Measure execution time of small code snippets"
55
 
             accesskey="N">next</a> |</li>
56
 
        <li class="right" >
57
 
          <a href="profile.html" title="26.4. The Python Profilers"
58
 
             accesskey="P">previous</a> |</li>
59
 
        <li><img src="../_static/py.png" alt=""
60
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
61
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
62
 
        <li>
63
 
          <span class="version_switcher_placeholder">2.7.11</span>
64
 
          <a href="../index.html">Documentation</a> &raquo;
65
 
        </li>
66
 
 
67
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
68
 
          <li class="nav-item nav-item-2"><a href="debug.html" accesskey="U">26. Debugging and Profiling</a> &raquo;</li> 
69
 
      </ul>
70
 
    </div>    
71
 
 
72
 
    <div class="document">
73
 
      <div class="documentwrapper">
74
 
        <div class="bodywrapper">
75
 
          <div class="body" role="main">
76
 
            
77
 
  <div class="section" id="module-hotshot">
78
 
<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"><span class="pre">hotshot</span></code></a> &#8212; High performance logging profiler<a class="headerlink" href="#module-hotshot" title="Permalink to this headline">¶</a></h1>
79
 
<div class="versionadded">
80
 
<p><span class="versionmodified">New in version 2.2.</span></p>
81
 
</div>
82
 
<p>This module provides a nicer interface to the <code class="xref py py-mod docutils literal"><span class="pre">_hotshot</span></code> C module. Hotshot
83
 
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"><span class="pre">profile</span></code></a> module. As it&#8217;s written mostly
84
 
in C, it should result in a much smaller performance impact than the existing
85
 
<a class="reference internal" href="profile.html#module-profile" title="profile: Python source profiler."><code class="xref py py-mod docutils literal"><span class="pre">profile</span></code></a> module.</p>
86
 
<div class="admonition note">
87
 
<p class="first admonition-title">Note</p>
88
 
<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"><span class="pre">hotshot</span></code></a> module focuses on minimizing the overhead while profiling, at
89
 
the expense of long data post-processing times. For common usage it is
90
 
recommended to use <a class="reference internal" href="profile.html#module-cProfile" title="cProfile"><code class="xref py py-mod docutils literal"><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"><span class="pre">hotshot</span></code></a> is not maintained and
91
 
might be removed from the standard library in the future.</p>
92
 
</div>
93
 
<div class="versionchanged">
94
 
<p><span class="versionmodified">Changed in version 2.5: </span>The results should be more meaningful than in the past: the timing core
95
 
contained a critical bug.</p>
96
 
</div>
97
 
<div class="admonition note">
98
 
<p class="first admonition-title">Note</p>
99
 
<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"><span class="pre">hotshot</span></code></a> profiler does not yet work well with threads. It is useful to
100
 
use an unthreaded script to run the profiler over the code you&#8217;re interested in
101
 
measuring if at all possible.</p>
102
 
</div>
103
 
<dl class="class">
104
 
<dt id="hotshot.Profile">
105
 
<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>
106
 
<dd><p>The profiler object. The argument <em>logfile</em> is the name of a log file to use for
107
 
logged profile data. The argument <em>lineevents</em> specifies whether to generate
108
 
events for every source line, or just on function call/return. It defaults to
109
 
<code class="docutils literal"><span class="pre">0</span></code> (only log function call/return). The argument <em>linetimings</em> specifies
110
 
whether to record timing information. It defaults to <code class="docutils literal"><span class="pre">1</span></code> (store timing
111
 
information).</p>
112
 
</dd></dl>
113
 
 
114
 
<div class="section" id="profile-objects">
115
 
<span id="hotshot-objects"></span><h2>26.5.1. Profile Objects<a class="headerlink" href="#profile-objects" title="Permalink to this headline">¶</a></h2>
116
 
<p>Profile objects have the following methods:</p>
117
 
<dl class="method">
118
 
<dt id="hotshot.Profile.addinfo">
119
 
<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>
120
 
<dd><p>Add an arbitrary labelled value to the profile output.</p>
121
 
</dd></dl>
122
 
 
123
 
<dl class="method">
124
 
<dt id="hotshot.Profile.close">
125
 
<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>
126
 
<dd><p>Close the logfile and terminate the profiler.</p>
127
 
</dd></dl>
128
 
 
129
 
<dl class="method">
130
 
<dt id="hotshot.Profile.fileno">
131
 
<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>
132
 
<dd><p>Return the file descriptor of the profiler&#8217;s log file.</p>
133
 
</dd></dl>
134
 
 
135
 
<dl class="method">
136
 
<dt id="hotshot.Profile.run">
137
 
<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>
138
 
<dd><p>Profile an <a class="reference internal" href="../reference/simple_stmts.html#exec"><code class="xref std std-keyword docutils literal"><span class="pre">exec</span></code></a>-compatible string in the script environment. The
139
 
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"><span class="pre">__main__</span></code></a> module are used as both the globals and locals
140
 
for the script.</p>
141
 
</dd></dl>
142
 
 
143
 
<dl class="method">
144
 
<dt id="hotshot.Profile.runcall">
145
 
<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>
146
 
<dd><p>Profile a single call of a callable. Additional positional and keyword arguments
147
 
may be passed along; the result of the call is returned, and exceptions are
148
 
allowed to propagate cleanly, while ensuring that profiling is disabled on the
149
 
way out.</p>
150
 
</dd></dl>
151
 
 
152
 
<dl class="method">
153
 
<dt id="hotshot.Profile.runctx">
154
 
<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>
155
 
<dd><p>Evaluate an <a class="reference internal" href="../reference/simple_stmts.html#exec"><code class="xref std std-keyword docutils literal"><span class="pre">exec</span></code></a>-compatible string in a specific environment. The
156
 
string is compiled before profiling begins.</p>
157
 
</dd></dl>
158
 
 
159
 
<dl class="method">
160
 
<dt id="hotshot.Profile.start">
161
 
<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>
162
 
<dd><p>Start the profiler.</p>
163
 
</dd></dl>
164
 
 
165
 
<dl class="method">
166
 
<dt id="hotshot.Profile.stop">
167
 
<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>
168
 
<dd><p>Stop the profiler.</p>
169
 
</dd></dl>
170
 
 
171
 
</div>
172
 
<div class="section" id="module-hotshot.stats">
173
 
<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>
174
 
<div class="versionadded">
175
 
<p><span class="versionmodified">New in version 2.2.</span></p>
176
 
</div>
177
 
<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"><span class="pre">pstats</span></code></a> Stats
178
 
objects.</p>
179
 
<dl class="function">
180
 
<dt id="hotshot.stats.load">
181
 
<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>
182
 
<dd><p>Load hotshot data from <em>filename</em>. Returns an instance of the
183
 
<a class="reference internal" href="profile.html#pstats.Stats" title="pstats.Stats"><code class="xref py py-class docutils literal"><span class="pre">pstats.Stats</span></code></a> class.</p>
184
 
</dd></dl>
185
 
 
186
 
<div class="admonition seealso">
187
 
<p class="first admonition-title">See also</p>
188
 
<dl class="last docutils">
189
 
<dt>Module <a class="reference internal" href="profile.html#module-profile" title="profile: Python source profiler."><code class="xref py py-mod docutils literal"><span class="pre">profile</span></code></a></dt>
190
 
<dd>The <a class="reference internal" href="profile.html#module-profile" title="profile: Python source profiler."><code class="xref py py-mod docutils literal"><span class="pre">profile</span></code></a> module&#8217;s <code class="xref py py-class docutils literal"><span class="pre">Stats</span></code> class</dd>
191
 
</dl>
192
 
</div>
193
 
</div>
194
 
<div class="section" id="example-usage">
195
 
<span id="hotshot-example"></span><h2>26.5.3. Example Usage<a class="headerlink" href="#example-usage" title="Permalink to this headline">¶</a></h2>
196
 
<p>Note that this example runs the Python &#8220;benchmark&#8221; pystones.  It can take some
197
 
time to run, and will produce large output files.</p>
198
 
<div class="highlight-python"><div class="highlight"><pre><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>
199
 
<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>
200
 
<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>
201
 
<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>
202
 
<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>
203
 
<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>
204
 
<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>
205
 
<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>
206
 
<span class="go">         850004 function calls in 10.090 CPU seconds</span>
207
 
 
208
 
<span class="go">   Ordered by: internal time, call count</span>
209
 
 
210
 
<span class="go">   ncalls  tottime  percall  cumtime  percall filename:lineno(function)</span>
211
 
<span class="go">        1    3.295    3.295   10.090   10.090 pystone.py:79(Proc0)</span>
212
 
<span class="go">   150000    1.315    0.000    1.315    0.000 pystone.py:203(Proc7)</span>
213
 
<span class="go">    50000    1.313    0.000    1.463    0.000 pystone.py:229(Func2)</span>
214
 
<span class="go"> .</span>
215
 
<span class="go"> .</span>
216
 
<span class="go"> .</span>
217
 
</pre></div>
218
 
</div>
219
 
</div>
220
 
</div>
221
 
 
222
 
 
223
 
          </div>
224
 
        </div>
225
 
      </div>
226
 
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
227
 
        <div class="sphinxsidebarwrapper">
228
 
  <h3><a href="../contents.html">Table Of Contents</a></h3>
229
 
  <ul>
230
 
<li><a class="reference internal" href="#">26.5. <code class="docutils literal"><span class="pre">hotshot</span></code> &#8212; High performance logging profiler</a><ul>
231
 
<li><a class="reference internal" href="#profile-objects">26.5.1. Profile Objects</a></li>
232
 
<li><a class="reference internal" href="#module-hotshot.stats">26.5.2. Using hotshot data</a></li>
233
 
<li><a class="reference internal" href="#example-usage">26.5.3. Example Usage</a></li>
234
 
</ul>
235
 
</li>
236
 
</ul>
237
 
 
238
 
  <h4>Previous topic</h4>
239
 
  <p class="topless"><a href="profile.html"
240
 
                        title="previous chapter">26.4. The Python Profilers</a></p>
241
 
  <h4>Next topic</h4>
242
 
  <p class="topless"><a href="timeit.html"
243
 
                        title="next chapter">26.6. <code class="docutils literal"><span class="pre">timeit</span></code> &#8212; Measure execution time of small code snippets</a></p>
244
 
<h3>This Page</h3>
245
 
<ul class="this-page-menu">
246
 
  <li><a href="../bugs.html">Report a Bug</a></li>
247
 
  <li><a href="../_sources/library/hotshot.txt"
248
 
         rel="nofollow">Show Source</a></li>
249
 
</ul>
250
 
 
251
 
<div id="searchbox" style="display: none" role="search">
252
 
  <h3>Quick search</h3>
253
 
    <form class="search" action="../search.html" method="get">
254
 
      <input type="text" name="q" />
255
 
      <input type="submit" value="Go" />
256
 
      <input type="hidden" name="check_keywords" value="yes" />
257
 
      <input type="hidden" name="area" value="default" />
258
 
    </form>
259
 
    <p class="searchtip" style="font-size: 90%">
260
 
    Enter search terms or a module, class or function name.
261
 
    </p>
262
 
</div>
263
 
<script type="text/javascript">$('#searchbox').show(0);</script>
264
 
        </div>
265
 
      </div>
266
 
      <div class="clearer"></div>
267
 
    </div>  
268
 
    <div class="related" role="navigation" aria-label="related navigation">
269
 
      <h3>Navigation</h3>
270
 
      <ul>
271
 
        <li class="right" style="margin-right: 10px">
272
 
          <a href="../genindex.html" title="General Index"
273
 
             >index</a></li>
274
 
        <li class="right" >
275
 
          <a href="../py-modindex.html" title="Python Module Index"
276
 
             >modules</a> |</li>
277
 
        <li class="right" >
278
 
          <a href="timeit.html" title="26.6. timeit — Measure execution time of small code snippets"
279
 
             >next</a> |</li>
280
 
        <li class="right" >
281
 
          <a href="profile.html" title="26.4. The Python Profilers"
282
 
             >previous</a> |</li>
283
 
        <li><img src="../_static/py.png" alt=""
284
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
285
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
286
 
        <li>
287
 
          <span class="version_switcher_placeholder">2.7.11</span>
288
 
          <a href="../index.html">Documentation</a> &raquo;
289
 
        </li>
290
 
 
291
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
292
 
          <li class="nav-item nav-item-2"><a href="debug.html" >26. Debugging and Profiling</a> &raquo;</li> 
293
 
      </ul>
294
 
    </div>  
295
 
    <div class="footer">
296
 
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
297
 
    <br />
298
 
    The Python Software Foundation is a non-profit corporation.
299
 
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
300
 
    <br />
301
 
    Last updated on Jan 23, 2016.
302
 
    <a href="../bugs.html">Found a bug</a>?
303
 
    <br />
304
 
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
305
 
    </div>
306
 
 
307
 
  </body>
308
 
</html>
 
 
b'\\ No newline at end of file'