Created
October 13, 2011 04:22
-
-
Save amjith/1283366 to your computer and use it in GitHub Desktop.
Profiling decorator
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
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