Skip to content

Instantly share code, notes, and snippets.

@kitelife
Forked from amjith/profile_func.py
Created March 12, 2013 04:37
Show Gist options
  • Save kitelife/5140405 to your computer and use it in GitHub Desktop.
Save kitelife/5140405 to your computer and use it in GitHub Desktop.
def profile_func(filename=None):
def proffunc(f):
def profiled_func(*args, **kwargs):
import cProfile
import logging
logging.info('Profiling function %s' % (f.__name__))
try:
profiler = cProfile.Profile()
retval = profiler.runcall(f, *args, **kwargs)
profiler.dump_stats(filename or '%s_func.profile' % (f.__name__))
except IOError:
logging.exception(_("Could not open profile file '%(filename)s'") % {"filename": filename})
return retval
return profiled_func
return proffunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment