feat: improve pprof experience by adding wrappers to interpreted functions#1712
Open
david-garcia-garcia wants to merge 1 commit intotraefik:masterfrom
Open
feat: improve pprof experience by adding wrappers to interpreted functions#1712david-garcia-garcia wants to merge 1 commit intotraefik:masterfrom
david-garcia-garcia wants to merge 1 commit intotraefik:masterfrom
Conversation
2 tasks
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.
When profiling applications using Yaegi (e.g., Traefik with plugins), all interpreted functions appear as anonymous closures in pprof.
This makes profiling impossible. If there was a way of doing this, I could not find it.
I tried to solve this with pprof labels, but they are only supported in CPU analysis and not in memory heap analysis.
I also tried to use reflection to create named intermediate wrappers without success. This is limited or super complex in go (I've done this in the past in IL with .Net).
I am not happy on how little elegant the solution is. I tried to prioritize performance (plus I didn't find a way to accomplish this differently).
What I am doing is assign each anonymous function one of a preset of 500 pregenerated wrappers that will properly show in stack traces and dumps. Then the runtime exposes a method GetWrapperMappings() to get the mappings between these wrappers and the real function names and packages.
Memory overhead is minimal (~125 KB for 500 wrappers) and runtime overhead is also almost negligible.
If you run out of wrappers worst case you might have the more than one function mapped to the same wrapper, which is way better than current situation.
Results
CPU Profile
BEFORE this PR:
AFTER this PR:
Wrapper Mapping:
Heap/Allocation Profile
BEFORE this PR:
AFTER this PR:
Wrapper Mapping: