You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With #74 it is now possible to output stacks for visualization with flamegraph.pl or e.g. Speedscope. The latter respects stack order in the input file ("Time Order") by default.
PR #76 is an early attempt to introduce logical stack order: stacks are output in the order they were first encountered. Often it is a gross improvement over alphanumeric (as in flamegraph.pl) or frequency (as in Speedscope's "Left Heavy") sorting, as the logical flow of program is better preserved.
It is now proposed to implement a general algorithm and set of options to specify desired stack output order. Below is prototype code that post-processes py-spy stacks (with #74, #76 enabled). The implementation uses different (dict-of-dicts tree) data structure but should be ~ as efficient as currently-used HashMap of stack-hash->count.
stacks.txt (stack order by first occurrence, Output stacks in order they were encountered #76):
Stack order is mostly logical: getfixutevalue() followed by put() and then get(). Only in the end slice and spec stacks become "fragmented" (can be fixed by stackshuffle.py, see time.txt below).
alnum.txt (python stackshuffle.py --alnum < stacks.txt > alnum.txt):
Alphanumeric sorting, similar to what flamegraph.pl does.
Order illogical, e.g. get() before put(); but useful for locating particular function quickly.
heavy.txt (python stackshuffle.py --heavy < stacks.txt > heavy.txt):
Frequency descending sort order, similar to Speedscope's "Left Heavy".
Useful for quickly seeing most significant time eaters, but illogical (get() before put(), spec before slice, getfixturevalue() in the end).
With #74 it is now possible to output stacks for visualization with
flamegraph.pl
or e.g. Speedscope. The latter respects stack order in the input file ("Time Order") by default.PR #76 is an early attempt to introduce logical stack order: stacks are output in the order they were first encountered. Often it is a gross improvement over alphanumeric (as in
flamegraph.pl
) or frequency (as in Speedscope's "Left Heavy") sorting, as the logical flow of program is better preserved.It is now proposed to implement a general algorithm and set of options to specify desired stack output order. Below is prototype code that post-processes
py-spy
stacks (with #74, #76 enabled). The implementation uses different (dict-of-dicts tree) data structure but should be ~ as efficient as currently-usedHashMap
ofstack-hash
->count
.stackshuffle.py
The profiled code is basically
pytest
case with the following logic:To compare different sorting schemes, please drag-and-drop into https://www.speedscope.app:
Stack order is mostly logical:
getfixutevalue()
followed byput()
and thenget()
. Only in the endslice
andspec
stacks become "fragmented" (can be fixed bystackshuffle.py
, seetime.txt
below).python stackshuffle.py --alnum < stacks.txt > alnum.txt
):Alphanumeric sorting, similar to what
flamegraph.pl
does.Order illogical, e.g.
get()
beforeput()
; but useful for locating particular function quickly.python stackshuffle.py --heavy < stacks.txt > heavy.txt
):Frequency descending sort order, similar to Speedscope's "Left Heavy".
Useful for quickly seeing most significant time eaters, but illogical (
get()
beforeput()
,spec
beforeslice
,getfixturevalue()
in the end).python stackshuffle.py < stacks.txt > time.txt
):Program logical flow preserved perfectly :-)
Attached prototype
stackshuffle.py
implements the latter 3 options (different only by specification of sort functionkey
).I'm volunteering to integrate into py-spy! (after #74 lands in master)
The text was updated successfully, but these errors were encountered: