ionelmc / python-hunter

Hunter is a flexible code tracing toolkit.
https://python-hunter.readthedocs.io/
BSD 2-Clause "Simplified" License
794 stars 46 forks source link

Is it possible to set the depth of tracing and store the execution time of called functions? #94

Closed anki-code closed 3 years ago

anki-code commented 3 years ago

Hi! Great tool! Many thanks!

I tried to use hunter to dive into the xonsh shell. The code is complex and I want to asking an advice.

Is there a way to restrict the depth and add time of execution for a functions/constructors?

For example we have:

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

In trace with depth=1 we have:

c = 1
a() # 2 sec

In trace with depth=2 we have:

c = 1
a()
    time.sleep(2)  # 2 sec
    b=1
# end a() - 2 sec

The depth could allow to go from whole to the details.

Is it possible?

Thanks!

PS: Meanwhile if you have another advice how to deep dive into the complex code with tracing please feel free to share!

ionelmc commented 3 years ago

You can add operators, eg: depth_lt=5, see https://python-hunter.readthedocs.io/en/latest/filtering.html

About durations (profiling basically) - it's kinda complicated, see https://python-hunter.readthedocs.io/en/latest/cookbook.html#profiling

anki-code commented 3 years ago

Many thanks for the fast answer! I will dive into this.

anki-code commented 3 years ago

I'm leaving here the link to my small solution - https://github.com/anki-code/xunter

Thanks for the help! Hunter is awesome!

ionelmc commented 3 years ago

Nice. Looks like I have to make a "projects using hunter" section somewhere in the docs.

ionelmc commented 3 years ago

Added.

anki-code commented 3 years ago

@ionelmc thanks! You a bit forget about rst :) I've fixed in https://github.com/ionelmc/python-hunter/pull/95