Skip to content

Add --flamegraph flag for folded stack profile output#640

Merged
stephenamar-db merged 1 commit intomasterfrom
flamegraph
Mar 6, 2026
Merged

Add --flamegraph flag for folded stack profile output#640
stephenamar-db merged 1 commit intomasterfrom
flamegraph

Conversation

@stephenamar-db
Copy link
Copy Markdown
Collaborator

Summary

  • Adds a --flamegraph <file> CLI flag that writes a flame graph profile in Brendan Gregg's folded stack format
  • Introduces FlameGraphProfiler that hooks into the existing Evaluator stack depth tracking, pushing/popping frame names at every Apply, ApplyBuiltin, import, comprehension, and object field evaluation
  • Profile output can be fed directly into FlameGraph tools: flamegraph.pl profile.txt > profile.svg

Test plan

  • sjsonnet.jvm[3.3.7].test passes (140/140)
  • sjsonnet.jvm[2.13.18].compile passes
  • Manual testing: sjsonnet --flamegraph /tmp/profile.txt <input>.jsonnet produces valid folded stack output
Introduces a FlameGraphProfiler that records Jsonnet call stacks in
Brendan Gregg's folded stack format, suitable for generating flame
graphs. The profiler hooks into the existing stack depth tracking in
the Evaluator, pushing/popping frame names alongside depth checks.

Usage: sjsonnet --flamegraph profile.txt input.jsonnet
Then: flamegraph.pl profile.txt > profile.svg
@He-Pin
Copy link
Copy Markdown
Contributor

He-Pin commented Mar 6, 2026

cool, I was want to do that too

@stephenamar-db stephenamar-db merged commit 07dc5be into master Mar 6, 2026
7 of 8 checks passed
@stephenamar-db stephenamar-db deleted the flamegraph branch March 6, 2026 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants