123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <html> <head>
- <title>profile/cProfile as the module of the month</title>
- <style>
- body {
- background-color: #dacfcf;
- }
- .slide {
- font-family: Gill Sans;
- border: 2px solid #887777;
- background-color: #e7dada;;
- padding: 2%;
- width: 94%;
- }
- h1 {
- text-align: center;
- }
- pre {
- border: 1px solid #664444;
- background-color: #ffe8e8;
- padding: 2px;
- }
- </style>
- <script src="scripts/jquery-1.2.3.js" type="text/javascript"></script>
- <script src="scripts/slideshow.js" type="text/javascript"></script>
- </head>
- <body>
- <div class='slide'>
- <h1>profile/cProfile</h1>
- <p>John Melesky
- (PDX Python, May 2010)</p>
- </div>
- <div class='slide'>
- <h1>In the standard library</h1>
- <ul>
- <li>hotshot</li>
- <li>timeit</li>
- <li>profile/cprofile/pstats</li>
- </ul>
- </div>
- <div class='slide'>
- <h1>hotshot</h1>
- </div>
- <div class='slide'>
- <h1>timeit</h1>
- </div>
- <div class='slide'>
- <h1>profile/cProfile</h1>
- <p>Instead of:</p>
- <pre><code>if __name__ == '__main__':
- main()
- </code></pre>
- <p>Do:</p>
- <pre><code>if __name__ == '__main__':
- import cProfile
- cProfile.run('main()')
- </code></pre>
- </div>
- <div class='slide'>
- <h1>Questions?</h1>
- </div>
- <div class='slide'>
- <h1>Need more detail!</h1>
- </div>
- <div class='slide'>
- <h1>Need more detail!</h1>
- <p>Instead of:</p>
- <pre><code>if __name__ == '__main__':
- import cProfile
- cProfile.run('main()')
- </code></pre>
- <p>Do:</p>
- <pre><code>if __name__ == '__main__':
- import cProfile
- cProfile.run('main()', 'myinfo.prof')
- </code></pre>
- </div>
- <div class='slide'>
- <h1>side note</h1>
- <p>If you need to set up an environment, you can use <code>cProfile.runctx(command, globals, locals)</code>.</p>
- </div>
- <div class='slide'>
- <h1>Need more detail!</h1>
- <p>Then:</p>
- <pre><code>#!/usr/bin/env python
- import pstats
- p = pstats.Stats('myinfo.prof')
- p.strip_dirs().sort_stats("time").print_stats(50)
- </code></pre>
- </div>
- <div class='slide'>
- <h1>pstats</h1>
- <ul>
- <li><code>strip_dirs</code></li>
- <li><code>sort_stats</code>: "calls", "cumulative", "pcalls", "time", etc</li>
- <li><code>print_stats</code>: restrictable (number of rows, regular expression)</li>
- </ul>
- </div>
- <div class='slide'>
- <h1>pstats</h1>
- <p>Also:</p>
- <ul>
- <li><code>print_callers</code></li>
- <li><code>print_callees</code></li>
- <li><code>reverse_order</code></li>
- <li><code>dump_stats</code></li>
- </ul>
- </div>
- <div class='slide'>
- <h1>pstats</h1>
- <p>Finally:</p>
- <ul>
- <li><code>add</code></li>
- </ul>
- </div>
- <div class='slide'>
- <h1>Whine whine whine</h1>
- <p>It's only usable from the command line!</p>
- </div>
- <div class='slide'>
- <h1>It's been wrapped</h1>
- <p>See, for example, <a href="http://pypi.python.org/pypi/repoze.profile">repoze.profile</a>.</p>
- </div>
- <div class='slide'>
- <h1>Questions?</h1>
- </div>
- <div class='slide'>
- <p></p>
- </div>
- <div class='slide'>
- <p></p>
- </div>
- </body></html>
|