How to do per-line profiling?
Roy Smith
roy at panix.com
Sun Apr 13 14:38:28 EDT 2003
Alex Martelli <aleax at aleax.it> wrote:
> Yes, package hotshot (part of the standard Python library) is just
> such a tool. Unfortunately, it's somewhat under-documented!
Thanks for the pointer -- at least it got me looking in the right place.
Unfortunately, when I try to follow the examples from
http://www.python.org/dev/doc/devel//////lib/hotshot-example.html
I get:
Traceback (most recent call last):
File "./rulex-diff.py", line 604, in ?
stats = hotshot.stats.load ('profile-stats')
File "/usr/local/lib/python2.2/hotshot/stats.py", line 12, in load
return StatsLoader(filename).load()
File "/usr/local/lib/python2.2/hotshot/stats.py", line 51, in load
assert not self._stack
AssertionError
Here's what I tried:
import hotshot, hotshot.stats
import pstats
app = rulexDiffApp()
prof = hotshot.Profile ('profile-stats', 1, 1)
prof.run ('app.main()')
prof.close()
stats = hotshot.stats.load ('profile-stats')
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)
This is Python-2.2.2 on a RedHat 6.2 box.
More information about the Python-list
mailing list