using cProfile to profile a code with decorators have strange results

393 Views Asked by At

So i'm using cProfile and snakeviz to profil my code. My code has decorator which seems to make the cProfile results not very correct :

my code :

import time
import decorator


@decorator.decorator
def my_deco(f, *args, **kwargs):
    ret = f(*args, **kwargs)
    return ret

def a():
    time.sleep(2)
    b()
    c()

@my_deco
def b():
    time.sleep(3)
    d()

@my_deco
def c():
    time.sleep(1)
    d()
    
@my_deco
def d():
    time.sleep(3)


if __name__ == "__main__":
    a()

profiling without decorator (expected behavior) : In this case, b, c are at the same level and d bellow.

enter image description here

profiling with decorator (not wanted behavior) : In this case, b, c and d are at the same level.

enter image description here

0

There are 0 best solutions below