Skip to content

Instantly share code, notes, and snippets.

@dnouri
Created February 28, 2013 13:40
Show Gist options
  • Save dnouri/5056788 to your computer and use it in GitHub Desktop.
Save dnouri/5056788 to your computer and use it in GitHub Desktop.
A profile function decorator. Writes profile to <functionname>.profile. Inspect the profile with runsnakerun or the like.
import cProfile
from functools import wraps
def profile(func):
@wraps(func)
def wrapper(*args, **kwargs):
cProfile.runctx(
'result = func(*args, **kwargs)',
globals(),
locals(),
filename='%s.profile' % func.__name__,
)
return locals()['result']
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment