def do_cprofile(func):
def profiled_func(*args, **kwargs):<EOL><INDENT>profile = cProfile.Profile()<EOL>try:<EOL><INDENT>profile.enable()<EOL>result = func(*args, **kwargs)<EOL>profile.disable()<EOL>return result<EOL><DEDENT>finally:<EOL><INDENT>profile.print_stats()<EOL><DEDENT><DEDENT>return profiled_func<EOL>
Originally from https://zapier.com/engineering/profiling-python-boss/