Skip to content

Instantly share code, notes, and snippets.

@FZambia
Created November 17, 2012 17:49
Show Gist options
  • Save FZambia/4098133 to your computer and use it in GitHub Desktop.
Save FZambia/4098133 to your computer and use it in GitHub Desktop.
python function profile
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