line_profiler
line_profiler copied to clipboard
how can i profile all function running without mark them by @ profile
+1, would like to do this as well. It would be nice to have an API like:
import line_profiler
line_profiler.add_function(mymodule.func_name)
You can do this:
import mymodule
# Decorate mymodule.func_name with `@profile` but don't break if run outside
# kernprof (e.g. to get function timing without line profiling).
profile = __builtin__.__dict__.get('profile', lambda f: f)
mymodule.func_name = profile(mymodule.func_name)
or:
from mymodule import func_name
profile = __builtin__.__dict__.get('profile', lambda f: f)
func_name = profile(func_name)
func_name()