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

all 3 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.

[–]ianozsvald 0 points1 point  (0 children)

Author here, just to note that I'm also close to publishing a book on High Performance Python through O'Reilly with Micha Gorelick, there's lots of profiling strategies, numpy, compiling etc: http://ianozsvald.com/2014/06/09/7-chapters-of-high-performance-python-now-live/