How can I profile a python script with many decorated methods?

174 Views Asked by At

I'm using snakeviz/cProfile to view the profile data of a slow running python script.

However a lot of the longer running methods are wrapped with decorators and so I don't see the name of the function/method in the call but instead I see 'wrapped' (ie the name of the function given within the decorator, see trivial case below)

def my_decorator(func):
    def wrapped(args, kwargs)
       # do thing
       return func(*args, **kwargs)
    return wrapped

Is there a way to write my decorators to avoid this? Or a parameter to cProfile, snakeviz I'm missing? Would functools.wraps help?

0

There are 0 best solutions below