Skip to content

Instantly share code, notes, and snippets.

@roger-link
Created March 20, 2014 19:48
Show Gist options
  • Save roger-link/9672335 to your computer and use it in GitHub Desktop.
Save roger-link/9672335 to your computer and use it in GitHub Desktop.
Add pycallgraph to django middleware
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
@scotttaggart
Copy link

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment