bugfix for paste.debug.profile

1 view
Skip to first unread message

Jon Nelson

unread,
May 6, 2009, 1:22:39 PM5/6/09
to Paste Users
I know it's kinda-sorta deprecated, but it was useful and handy... so
I fixed it.

Presumably some version of Python changed the way the Pstats class
works (at *instantiation* time it stores a copy of sys.stdout and uses
that).

diff --git a/paste/debug/profile.py b/paste/debug/profile.py
index 8e2d40a..aaf6249 100644
--- a/paste/debug/profile.py
+++ b/paste/debug/profile.py
@@ -74,9 +74,19 @@ class ProfileMiddleware(object):
stats = hotshot.stats.load(self.log_filename)
stats.strip_dirs()
stats.sort_stats('time', 'calls')
- output = capture_output(stats.print_stats, self.limit)
- output_callers = capture_output(
- stats.print_callers, self.limit)
+ if hasattr(stats, 'stream'):
+ oldstream = stats.stream
+ stats.stream = StringIO()
+ stats.print_stats(self.limit)
+ output = stats.stream.getvalue()
+ stats.stream = StringIO()
+ stats.print_callers(self.limit)
+ output_callers = stats.stream.getvalue()
+ stats.stream = oldstream
+ else:
+ output = capture_output(stats.print_stats, self.limit)
+ output_callers = capture_output(
+ stats.print_callers, self.limit)
body += '<pre style="%s">%s\n%s</pre>' % (
self.style, cgi.escape(output), cgi.escape(output_callers))
return [body]


--
Jon

Reply all
Reply to author
Forward
0 new messages