1
'''Profiling middleware for paste.'''
5
from bzrlib.lsprof import profile
7
class LSProfMiddleware(object):
8
'''Paste middleware for profiling with lsprof.'''
10
def __init__(self, app, global_conf=None):
12
self.lock = threading.Lock()
15
def __run_app(self, environ, start_response):
16
app_iter = self.app(environ, start_response)
20
if getattr(app_iter, 'close', None):
23
def __call__(self, environ, start_response):
27
ret, stats = profile(self.__run_app, environ, start_response)
29
stats.save("%d-stats.callgrind" % self.__count, format="callgrind")