Conversation
newSourcePrinter accumulated cum[addr] += value for every frame of every sample. For a recursive function the same address is on the stack many times within one sample, so the sample was added to that address once per frame. Count each address at most once per sample instead, the same way newGraph does with its seenNode set. flat is only accumulated for the leaf frame, so it is unaffected. Updates google#707.
The cumulative value of a function in the list, disasm and weblist outputs, and of a line in weblist, was the sum of the cumulative values of its parts. A sample of a recursive function is included in several of those parts, so it was counted several times and the totals could exceed 100%. Count each sample once per function and per line instead. Updates google#707.
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes #707. Stacked on #1030: the first commit here is that PR, and only the second commit is new. I'll rebase once #1030 is in. The analysis is in #707 (comment).
The cumulative value shown for a function by
-list,-disasmand-weblist, and for a line by-weblist, was the sum of the cumulative values of its parts (fns.Sum(),sns.Sum(), and the per-instruction sums in source.go). cum is the weight of a set of samples, and those don't add: a sample of a recursive function reaches several lines and instructions of the function, so it was counted once for each of them.-liston a recursivefib:The per-line values are right (line 13 is exactly what
-topreports for the function); the header is 130 + 20 + 20 + 300.This adds
cumByGroup, which walks the samples once and adds each sample at most once to every group it touches, the same waynewGraphusesseenNode. The groups are (function, file) for-list, the symbol for-disasm, and lines and functions for weblist.Results on the
fibprofile (total 310ms,-topsays 300ms / 96.77%):Without recursion nothing changes:
-list=.,-disasm=.and-weblist=.on testdata/sample.bin + sample.cpu are byte-for-byte identical before and after. The only existing expectation that moves is the recursiveteein testdata/source.rpt, from 189.90% to 99.90%. Counting by hand, the samples containingteeare worth 100 + 1000 + 10000 = 11100 of 11111; the old 21100 counted the 10000 sample twice because it hasteeon two lines.It stays linear in the number of frames.
-weblist=.on a copy of sample.cpu inflated to 76,000 samples takes 0.33s before and 0.35s after. A first prototype that rescanned the samples for every line took 2.7s, which is why weblist now works out its functions up front and counts all lines and functions in one pass.New tests: weblist line and function totals, and a
-disasmheader through a small fake ObjTool. Both fail without this change (function cum 15 instead of 5, line cum 10 instead of 5).Things I'd like a second opinion on:
cumByGroupis generic because the three callers have different key types. The alternative is the same loop written three times.-listheader is per (function, file), not per function.main.busyLoopin sample.cpu appears under two files because of inlining, and keying on the function alone gives both of them 100%.-topreports. If that isn't what you want from these views, tell me and I'll close this.