Created
November 17, 2012 17:49
-
-
Save FZambia/4098133 to your computer and use it in GitHub Desktop.
python function profile
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 tempfile | |
import hotshot | |
import hotshot.stats | |
def profile(func): | |
def wrapper(request, *args, **kwargs): | |
tmpfile = tempfile.NamedTemporaryFile() | |
prof = hotshot.Profile(tmpfile.name) | |
result = prof.runcall(func, request, *args, **kwargs) | |
prof.close() | |
stats = hotshot.stats.load(tmpfile.name) | |
stats.strip_dirs() | |
stats.sort_stats('time','calls',) | |
stats.print_stats() | |
return result | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment