pyinstrument icon indicating copy to clipboard operation
pyinstrument copied to clipboard

Add option to show total time including children in flat profiles

Open matt-graham opened this issue 2 years ago • 1 comments

Adds a literal string argument flat_time to ConsoleRenderer which can be used to set frame time type displayed (and used as sort key) in flat profiles - "self" for total self time, excluding child frames (the default, equivalent to current behaviour) and "total" for total time, including child frames.

I find being able to view a flat list sorted by total time useful in some situations, but it does result in the less intutitive behaviour that the sum of the times shown no longer bears any relation to total run time.

Rather than a string argument could alternatively use a boolean flag if preferred or change name of options.

matt-graham avatar Dec 15 '23 14:12 matt-graham

For the remaining pyright error in pre-commit workflow, I get the same error when running pre-commit run --all-files locally on current tip of main so not sure if the failure is related to changes in this PR or a change in upstream packages?

matt-graham avatar Dec 15 '23 15:12 matt-graham

Could you add the option to Profiler.print and Profiler.output_text, too?

flat_time option now also exposed in Profiler.print and Profiler.output_text. I created a type alias FlatTimeMode to avoid repetition of the allowable string modes in the type hint and this seemed to mirror the pattern used for AsyncMode in profiler.py but let me know if you prefer this to be named differently.

matt-graham avatar Aug 01 '24 09:08 matt-graham