Created
August 5, 2011 05:00
-
-
Save wayhome/1126941 to your computer and use it in GitHub Desktop.
profile patch for tornado
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Monkey Patch for tornado | |
""" | |
import cProfile as profile | |
from tornado.options import options | |
from tornado.web import HTTPError | |
def profile_patch(execute): | |
def _(self, transforms, *args, **kwargs): | |
if options.is_debug and options.is_profile: | |
self.profiler = profile.Profile() | |
result = self.profiler.runcall(execute, self,transforms,*args, **kwargs) | |
self.profiler.dump_stats(options.PROFILE_FILE) | |
return result | |
else: | |
return execute(self, transforms, *args, **kwargs) | |
return _ | |
from tornado import web | |
old_execute = web.RequestHandler._execute | |
web.RequestHandler._execute = profile_patch(old_execute) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment