## #4 New sort option: Time relative to heaviest child.

open
nobody
None
5
2011-12-11
2011-12-11
Anonymous
No

I would like to see a new sort option, that really helps to find those function calls that are the most relevant to look at for optimization.

Example 1:
foo() needs 510ms to run.
foo() calls bar(), which needs 500ms to run.
-> foo() is not interesting to look at, because the interesting stuff happens in bar().

Example 2:
foo() needs 510 ms to run.
foo() calls bar_a(), which needs 200 ms.
foo() also calls bar_b(), which needs 300 ms.
-> foo() _is_ interesting to look at, because a big part of the duration is "branched" between two child function calls.

Example 3:
foo() needs 510 ms to run.
foo() calls bar() 50 times, where each call needs 10 ms.
-> foo() _is_ interesting to look at. We can ask ourselves why bar() has to run so often.

Example 4:
foo() needs 510 ms to run.
foo() calls bar(), but bar() only needs 100 ms.
the other 410 ms are in foo() itself.
-> foo() is interesting to look at, because it probably contains an insane loop.

Example 5:
foo() needs 510 ms to run.
foo() calls itself 2x, and each call needs 250 ms. What follows is a big recursion.
-> foo() is interesting to look at.

Example 6:
foo() needs 510 ms to run.
foo() calls itself 1x, and this call needs 500 ms. What follows is a big recursion.
-> Duh. We want to spot the recursion, but which instance of foo() should we look at? Anyway, this is somewhat interesting to look at.

So, what is a good sort measure, that will push foo to the top of the list, for Examples 2-5, but will put it to the bottom of the list for Example 1.
Existing sort options fail, imo.

--------

Proposed measure:
Take the duration of the function call to foo(), and subtract the duration of the longest-enduring child call.
Accumulate this value, for all calls to foo().

Example results:
Ex. 1) 10 ms for single call
Ex. 2) 200 ms for single call
Ex. 3) 500 ms for single call
Ex. 4) 410 ms for single call
Ex. 5) 260 ms for single call, + more for recursive calls.
Ex. 6) 10 ms for single call, + a lot more for recursive calls.

One could even invent something new for the recursion stuff, but then we'd also need to consider indirect recursion etc.
So we should rather stick with this simple measure, and see where it leads us.