summaryrefslogtreecommitdiff
path: root/cherrypy/lib/profiler.py
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2008-06-23 00:32:32 +0000
committerRobert Brewer <fumanchu@aminus.org>2008-06-23 00:32:32 +0000
commit49b2999a99a6ceed6cd3441a4be239ab672c276c (patch)
treeafb7c6dcaf2052c55ba6709a313d072a1777079f /cherrypy/lib/profiler.py
parentb18edbd69ccf6e4046c8bf113f4b5d63ef88814a (diff)
downloadcherrypy-git-49b2999a99a6ceed6cd3441a4be239ab672c276c.tar.gz
Fix for #827 (Profile viewer doesn't work with Python2.5).
Diffstat (limited to 'cherrypy/lib/profiler.py')
-rw-r--r--cherrypy/lib/profiler.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/cherrypy/lib/profiler.py b/cherrypy/lib/profiler.py
index 9b7db8be..9d5481dd 100644
--- a/cherrypy/lib/profiler.py
+++ b/cherrypy/lib/profiler.py
@@ -94,15 +94,24 @@ class Profiler(object):
def stats(self, filename, sortby='cumulative'):
"""stats(index) -> output of print_stats() for the given profile."""
- s = pstats.Stats(os.path.join(self.path, filename))
- s.strip_dirs()
- s.sort_stats(sortby)
- oldout = sys.stdout
- try:
- sys.stdout = sio = StringIO.StringIO()
+ sio = StringIO.StringIO()
+ if sys.version_info >= (2, 5):
+ s = pstats.Stats(os.path.join(self.path, filename), stream=sio)
+ s.strip_dirs()
+ s.sort_stats(sortby)
s.print_stats()
- finally:
- sys.stdout = oldout
+ else:
+ # pstats.Stats before Python 2.5 didn't take a 'stream' arg,
+ # but just printed to stdout. So re-route stdout.
+ s = pstats.Stats(os.path.join(self.path, filename))
+ s.strip_dirs()
+ s.sort_stats(sortby)
+ oldout = sys.stdout
+ try:
+ sys.stdout = sio
+ s.print_stats()
+ finally:
+ sys.stdout = oldout
response = sio.getvalue()
sio.close()
return response