Created
February 10, 2015 12:32
-
-
Save a-milogradov/e69fd3d4cb36bc60c170 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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