Skip to content

Instantly share code, notes, and snippets.

@a-milogradov
Created February 10, 2015 12:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-milogradov/e69fd3d4cb36bc60c170 to your computer and use it in GitHub Desktop.
Save a-milogradov/e69fd3d4cb36bc60c170 to your computer and use it in GitHub Desktop.
class SomeView(View):
def dispatch(self, request, *args, **kwargs):
# imports and start profiling
import cProfile, pstats, StringIO
pr = cProfile.Profile()
pr.enable()
# all logic runs here
response = super(SomeView, self).dispatch(request, *args, **kwargs)
# stop profiling and output to console
s = StringIO.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
print s.getvalue()
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment