line_profiler icon indicating copy to clipboard operation
line_profiler copied to clipboard

how can i profile all function running without mark them by @ profile

Open Zeye1 opened this issue 8 years ago • 2 comments

Zeye1 avatar Aug 05 '16 15:08 Zeye1

+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)

ddasilva avatar Jan 09 '17 21:01 ddasilva

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()

1fish2 avatar Mar 24 '18 04:03 1fish2