index.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <html> <head>
  2. <title>profile/cProfile as the module of the month</title>
  3. <style>
  4. body {
  5. background-color: #dacfcf;
  6. }
  7. .slide {
  8. font-family: Gill Sans;
  9. border: 2px solid #887777;
  10. background-color: #e7dada;;
  11. padding: 2%;
  12. width: 94%;
  13. }
  14. h1 {
  15. text-align: center;
  16. }
  17. pre {
  18. border: 1px solid #664444;
  19. background-color: #ffe8e8;
  20. padding: 2px;
  21. }
  22. </style>
  23. <script src="scripts/jquery-1.2.3.js" type="text/javascript"></script>
  24. <script src="scripts/slideshow.js" type="text/javascript"></script>
  25. </head>
  26. <body>
  27. <div class='slide'>
  28. <h1>profile/cProfile</h1>
  29. <p>John Melesky
  30. (PDX Python, May 2010)</p>
  31. </div>
  32. <div class='slide'>
  33. <h1>In the standard library</h1>
  34. <ul>
  35. <li>hotshot</li>
  36. <li>timeit</li>
  37. <li>profile/cprofile/pstats</li>
  38. </ul>
  39. </div>
  40. <div class='slide'>
  41. <h1>hotshot</h1>
  42. </div>
  43. <div class='slide'>
  44. <h1>timeit</h1>
  45. </div>
  46. <div class='slide'>
  47. <h1>profile/cProfile</h1>
  48. <p>Instead of:</p>
  49. <pre><code>if __name__ == '__main__':
  50. main()
  51. </code></pre>
  52. <p>Do:</p>
  53. <pre><code>if __name__ == '__main__':
  54. import cProfile
  55. cProfile.run('main()')
  56. </code></pre>
  57. </div>
  58. <div class='slide'>
  59. <h1>Questions?</h1>
  60. </div>
  61. <div class='slide'>
  62. <h1>Need more detail!</h1>
  63. </div>
  64. <div class='slide'>
  65. <h1>Need more detail!</h1>
  66. <p>Instead of:</p>
  67. <pre><code>if __name__ == '__main__':
  68. import cProfile
  69. cProfile.run('main()')
  70. </code></pre>
  71. <p>Do:</p>
  72. <pre><code>if __name__ == '__main__':
  73. import cProfile
  74. cProfile.run('main()', 'myinfo.prof')
  75. </code></pre>
  76. </div>
  77. <div class='slide'>
  78. <h1>side note</h1>
  79. <p>If you need to set up an environment, you can use <code>cProfile.runctx(command, globals, locals)</code>.</p>
  80. </div>
  81. <div class='slide'>
  82. <h1>Need more detail!</h1>
  83. <p>Then:</p>
  84. <pre><code>#!/usr/bin/env python
  85. import pstats
  86. p = pstats.Stats('myinfo.prof')
  87. p.strip_dirs().sort_stats("time").print_stats(50)
  88. </code></pre>
  89. </div>
  90. <div class='slide'>
  91. <h1>pstats</h1>
  92. <ul>
  93. <li><code>strip_dirs</code></li>
  94. <li><code>sort_stats</code>: "calls", "cumulative", "pcalls", "time", etc</li>
  95. <li><code>print_stats</code>: restrictable (number of rows, regular expression)</li>
  96. </ul>
  97. </div>
  98. <div class='slide'>
  99. <h1>pstats</h1>
  100. <p>Also:</p>
  101. <ul>
  102. <li><code>print_callers</code></li>
  103. <li><code>print_callees</code></li>
  104. <li><code>reverse_order</code></li>
  105. <li><code>dump_stats</code></li>
  106. </ul>
  107. </div>
  108. <div class='slide'>
  109. <h1>pstats</h1>
  110. <p>Finally:</p>
  111. <ul>
  112. <li><code>add</code></li>
  113. </ul>
  114. </div>
  115. <div class='slide'>
  116. <h1>Whine whine whine</h1>
  117. <p>It's only usable from the command line!</p>
  118. </div>
  119. <div class='slide'>
  120. <h1>It's been wrapped</h1>
  121. <p>See, for example, <a href="http://pypi.python.org/pypi/repoze.profile">repoze.profile</a>.</p>
  122. </div>
  123. <div class='slide'>
  124. <h1>Questions?</h1>
  125. </div>
  126. <div class='slide'>
  127. <p></p>
  128. </div>
  129. <div class='slide'>
  130. <p></p>
  131. </div>
  132. </body></html>