Created
March 20, 2014 19:48
-
-
Save roger-link/9672335 to your computer and use it in GitHub Desktop.
Add pycallgraph to django middleware
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
import time | |
from pycallgraph import PyCallGraph | |
from pycallgraph.output import GraphvizOutput | |
class CallgraphMiddleware(object): | |
def process_view(self, request, callback, callback_args, callback_kwargs): | |
if settings.DEBUG and 'graph' in request.GET: | |
pycallgraph = PyCallGraph(output=GraphvizOutput(output_file='callgraph-' + str(time.time()) + '.png')) | |
pycallgraph.start() | |
self.pycallgraph = pycallgraph | |
def process_response(self, request, response): | |
if settings.DEBUG and 'graph' in request.GET: | |
self.pycallgraph.done() | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!!