Prototype: Rudimentary stack profiler#529
Draft
igorwwwwwwwwwwwwwwwwwwww wants to merge 1 commit intogoogle:masterfrom
Draft
Prototype: Rudimentary stack profiler#529igorwwwwwwwwwwwwwwwwwwww wants to merge 1 commit intogoogle:masterfrom
igorwwwwwwwwwwwwwwwwwwww wants to merge 1 commit intogoogle:masterfrom
Conversation
Usage: JSONNET_STACK_PROFILE=stacks.out jsonnet main.jsonnet cat stacks.out | flamegraph.pl --hash > flamegraph.svg
Contributor
|
This is very interesting. I was thinking about doing something like that myself, but didn't have much time recently. I'd like to refactor it slightly (eliminate globals, extract all profiling logic to a separate function, so that in the normal flow it's just one check and one function call). Otherwise it looks good. |
This was referenced Apr 6, 2025
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.
We have a relatively large jsonnet code base (source), and I was trying to profile slow jsonnet invocations.
The golang-level profile via
JSONNET_CPU_PROFILEwasn't very helpful in this regard. And tracing individual calls by addingstd.tracewas quite combersome.I prototyped a little sampling stack profiler. It is not very sophisticated. It samples stacks for 1% of calls to
EvalInCleanEnv. Those stacks can then be visualised as a flamegraph.Usage:
There's plenty of room for improvement:
That said, the results I got from it so far look quite usable.
It's unlikely that I'll have much time to work on this and develop it into a fully-fledged solution.
I wanted to share what I have in case it's useful for others, or in case someone feels inspired to take the idea and develop it further.