| OLD | NEW |
| 1 """Profiler tools for CherryPy. | 1 """Profiler tools for CherryPy. |
| 2 | 2 |
| 3 CherryPy users | 3 CherryPy users |
| 4 ============== | 4 ============== |
| 5 | 5 |
| 6 You can profile any of your pages as follows: | 6 You can profile any of your pages as follows: |
| 7 | 7 |
| 8 from cherrypy.lib import profile | 8 from cherrypy.lib import profile |
| 9 | 9 |
| 10 class Root: | 10 class Root: |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 prof.runcall(func, *args) | 80 prof.runcall(func, *args) |
| 81 prof.dump_stats(path) | 81 prof.dump_stats(path) |
| 82 | 82 |
| 83 def statfiles(self): | 83 def statfiles(self): |
| 84 """statfiles() -> list of available profiles.""" | 84 """statfiles() -> list of available profiles.""" |
| 85 return [f for f in os.listdir(self.path) | 85 return [f for f in os.listdir(self.path) |
| 86 if f.startswith("cp_") and f.endswith(".prof")] | 86 if f.startswith("cp_") and f.endswith(".prof")] |
| 87 | 87 |
| 88 def stats(self, filename, sortby='cumulative'): | 88 def stats(self, filename, sortby='cumulative'): |
| 89 """stats(index) -> output of print_stats() for the given profile.""" | 89 """stats(index) -> output of print_stats() for the given profile.""" |
| 90 s = pstats.Stats(os.path.join(self.path, filename)) | 90 sio = StringIO.StringIO() |
| 91 kwds = {} |
| 92 if sys.version_info >= (2, 5): |
| 93 kwds['stream'] = sio |
| 94 s = pstats.Stats(os.path.join(self.path, filename), **kwds) |
| 91 s.strip_dirs() | 95 s.strip_dirs() |
| 92 s.sort_stats(sortby) | 96 s.sort_stats(sortby) |
| 93 oldout = sys.stdout | 97 if sys.version_info >= (2, 5): |
| 94 try: | 98 s.print_stats() |
| 95 sys.stdout = sio = StringIO.StringIO() | 99 else: |
| 96 s.print_stats() | 100 oldout = sys.stdout |
| 97 finally: | 101 try: |
| 98 sys.stdout = oldout | 102 sys.stdout = sio |
| 103 s.print_stats() |
| 104 finally: |
| 105 sys.stdout = oldout |
| 99 response = sio.getvalue() | 106 response = sio.getvalue() |
| 100 sio.close() | 107 sio.close() |
| 101 return response | 108 return response |
| 102 | 109 |
| 103 def index(self): | 110 def index(self): |
| 104 return """<html> | 111 return """<html> |
| 105 <head><title>CherryPy profile data</title></head> | 112 <head><title>CherryPy profile data</title></head> |
| 106 <frameset cols='200, 1*'> | 113 <frameset cols='200, 1*'> |
| 107 <frame src='menu' /> | 114 <frame src='menu' /> |
| 108 <frame name='main' src='' /> | 115 <frame name='main' src='' /> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 134 'server.thread_pool': 10, | 141 'server.thread_pool': 10, |
| 135 'server.environment': "production", | 142 'server.environment': "production", |
| 136 'session.storageType': "ram", | 143 'session.storageType': "ram", |
| 137 }) | 144 }) |
| 138 cherrypy.server.start() | 145 cherrypy.server.start() |
| 139 | 146 |
| 140 | 147 |
| 141 if __name__ == "__main__": | 148 if __name__ == "__main__": |
| 142 serve(*tuple(sys.argv[1:])) | 149 serve(*tuple(sys.argv[1:])) |
| 143 | 150 |
| OLD | NEW |