def __call__(self, environ, start_response): """Run a request.""" self.lock.acquire() try: ret, stats = profile(self.__run_app, environ, start_response) self.__count += 1 stats.save("%d-stats.callgrind" % (self.__count,), format="callgrind") return ret finally: self.lock.release()
def apply_lsprofiled(filename, the_callable, *args, **kwargs): from breezy.lsprof import profile ret, stats = profile(exception_to_return_code, the_callable, *args, **kwargs) stats.sort() if filename is None: stats.pprint() else: stats.save(filename) trace.note(gettext('Profile data written to "%s".'), filename) return ret