1
'''Profiling middleware for paste.'''
7
from bzrlib.lsprof import profile
10
class LSProfMiddleware(object):
11
'''Paste middleware for profiling with lsprof.'''
13
def __init__(self, app, global_conf=None):
15
self.lock = threading.Lock()
18
def __run_app(self, environ, start_response):
19
app_iter = self.app(environ, start_response)
23
if getattr(app_iter, 'close', None):
26
def __call__(self, environ, start_response):
30
ret, stats = profile(self.__run_app, environ, start_response)
32
stats.save("%d-stats.callgrind" % self.__count, format="callgrind")