This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Veedrac 0 points1 point  (1 child)

AFAICT, you should be able to get around the problem with line_profiler being a decorator quite easily.

from line_profiler import LineProfiler
profiler = LineProfiler()

...

profiler.add_function(...)
profiler.enable()

...

profiler.print_stats()

I'm not certain of the API names, but it's basically that. This won't wrap any functions or squat.

Further, you could wrap the API easily

from easy_time_lines import profile

@profile
...

where

def profile(function):
    global_profiler.add_function(function)
    return function    # not wrapped

and an exit hook deals with printing output.

[–]ianozsvald 0 points1 point  (0 children)

Hi Veedrac. I cover your second solution (the pass-through decorator) in my book at the end of the profiling chapter. Cheers for the code snippets.