joerick / pyinstrument

🚴 Call stack profiler for Python. Shows you why your code is slow!
https://pyinstrument.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
6.44k stars 227 forks source link

recursive functions #293

Open dpinol opened 6 months ago

dpinol commented 6 months ago

pyinstrument is a wonderful tool, but it's challenging to use on recursive functions

image

In this case, it's difficult to estimate the sum of the time spent on other functions called by the recursive functions (the ones at the bottom on the following snapshot)

Is there any way of obtaining the flat or cum times (as here) of the most sampled functions?

thanks

joerick commented 6 months ago

You could try the 'flat' option on the console renderer - e.g. pyinstrument -p flat myscript.py - that will print the output without any tree at all.

gnuille commented 6 months ago

I created a pull request so it can be enabled from api https://github.com/joerick/pyinstrument/pull/294

joerick commented 2 months ago

You can, if you like, use the output method, e.g. profiler.output(ConsoleRenderer(flat=True)). But your PR looks good too.