diff options
author | Robert Brewer <fumanchu@aminus.org> | 2006-07-10 06:25:49 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2006-07-10 06:25:49 +0000 |
commit | 02f4c21a36555d29df15f3bc034d9774060854fc (patch) | |
tree | b05651e98d876811ab23ad99a388a58f2fce3dc7 /cherrypy/lib/profiler.py | |
parent | 27268213fdb9573873af863222c8e478be6a2ff5 (diff) | |
download | cherrypy-git-02f4c21a36555d29df15f3bc034d9774060854fc.tar.gz |
Moved profiling into WSGI middleware.
Diffstat (limited to 'cherrypy/lib/profiler.py')
-rw-r--r-- | cherrypy/lib/profiler.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/cherrypy/lib/profiler.py b/cherrypy/lib/profiler.py index cdcfbe39..852def60 100644 --- a/cherrypy/lib/profiler.py +++ b/cherrypy/lib/profiler.py @@ -77,8 +77,9 @@ class Profiler(object): self.count += 1 path = os.path.join(self.path, "cp_%04d.prof" % self.count) prof = profile.Profile() - prof.runcall(func, *args) + result = prof.runcall(func, *args) prof.dump_stats(path) + return result def statfiles(self): """statfiles() -> list of available profiles.""" @@ -127,6 +128,21 @@ class Profiler(object): report.exposed = True +class make_app: + def __init__(self, nextapp, path=None): + """Make a WSGI middleware app which wraps 'nextapp' with profiling.""" + self.nextapp = nextapp + self.profiler = Profiler(path) + + def __call__(self, environ, start_response): + def gather(): + result = [] + for line in self.nextapp(environ, start_response): + result.append(line) + return result + return self.profiler.run(gather) + + def serve(path=None, port=8080): import cherrypy cherrypy.tree.mount(Profiler(path)) |