Created
October 21, 2015 19:04
-
-
Save sibelius/3920b3eb5adab482b105 to your computer and use it in GitHub Desktop.
Line Profiler decorator, it works on pure Python or Web frameworks like Flask or Django
This file contains 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
try: | |
from line_profiler import LineProfiler | |
def do_profile(follow=[]): | |
def inner(func): | |
def profiled_func(*args, **kwargs): | |
try: | |
profiler = LineProfiler() | |
profiler.add_function(func) | |
for f in follow: | |
profiler.add_function(f) | |
profiler.enable_by_count() | |
return func(*args, **kwargs) | |
finally: | |
profiler.print_stats() | |
return profiled_func | |
return inner | |
except ImportError: | |
def do_profile(follow=[]): | |
def inner(func): | |
def nothing(*args, **kwargs): | |
return func(*args, **kwargs) | |
return nothing | |
return inner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment