pyinstrument icon indicating copy to clipboard operation
pyinstrument copied to clipboard

Improve the experience with recursive functions

Open dpinol opened this issue 1 year ago • 4 comments

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

dpinol avatar Feb 28 '24 16:02 dpinol

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.

joerick avatar Feb 28 '24 16:02 joerick

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

gnuille avatar Mar 05 '24 13:03 gnuille

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

joerick avatar Jun 27 '24 08:06 joerick

I'm keeping this as an issue in the tracker, because it might be a good idea if the stack sampler condensed recursion into a [recursion] synthetic frame after 1-3 instances of the same frame identifier.

joerick avatar May 24 '25 15:05 joerick