Skip to content

feat: generate flamegraphs on demand#122

Draft
ivan-tymoshenko wants to merge 12 commits intomainfrom
force-flamegraph-generation
Draft

feat: generate flamegraphs on demand#122
ivan-tymoshenko wants to merge 12 commits intomainfrom
force-flamegraph-generation

Conversation

@ivan-tymoshenko
Copy link
Copy Markdown
Member

@ivan-tymoshenko ivan-tymoshenko commented Nov 26, 2025

This PR refactors the flamegraphs plugin from an always-on profiling model to an on-demand architecture. Instead of continuously profiling all workers at fixed intervals, profiling now starts only when explicitly
requested (via alerts, health signals, or WebSocket commands) and automatically stops when idle.

Previously, workers were profiled continuously and the eluThreshold setting determined whether profiles should be captured based on Event Loop Utilization. With on-demand profiling, the ELU threshold logic has been
removed entirely—profiles are now generated whenever requested, regardless of current utilization metrics. This gives callers explicit control over when profiling occurs rather than relying on automatic threshold-based
triggering.

Multiple profile requests are queued and associated with generated profiles based on timestamps. Profilers automatically stop after an idle period if no new requests arrive, preventing unnecessary resource consumption.

Copy link
Copy Markdown
Member

@Qard Qard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion, but otherwise LGTM.

Comment thread test/profiler.test.js
await profiler.requestProfile({ alertId: 'test-alert' })

// Wait for profile to be generated (duration is 1 second)
await sleep(1500)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than using plain await sleep(...) all over the place, delaying test completions longer than may actually be necessary, we might want to use a Promise.race(...) pattern for waiting on a completion condition with a timeout for failure. Something like:

await Promise.race([
  sleep(1500).then(() => Promise.reject('timeout')),
  profileReceivedPromise
])

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants