Skip to content

Fix flame chart tree building, layout, and add metric selection#312

Merged
butschster merged 3 commits intomasterfrom
fix/profiler-flamechart
Mar 26, 2026
Merged

Fix flame chart tree building, layout, and add metric selection#312
butschster merged 3 commits intomasterfrom
fix/profiler-flamechart

Conversation

@butschster
Copy link
Copy Markdown
Member

Summary

  • Fix PrepareEdges parent resolution: rewrote with two-pass approach — first builds a complete callee→edgeId map, then resolves parent references. Eliminates the $prev fallback that linked edges to wrong parents when the caller hadn't been processed yet. BFS ordering ensures parents always precede children.
  • Fix adjustStartTimes overflow: if children's total duration exceeds the parent block, they are now scaled down proportionally instead of overflowing.
  • Parameterize flame chart metric: was hardcoded to wt (wall time). Now accepts metric from frontend (wt, cpu, mu, pmu) with metric-appropriate divisor (μs→ms for time, bytes→KB for memory). Metric is included in cache key.
  • Add ct to percentage calculation in PrepareEdges (p_ct was always 0).

Test plan

  • PHPUnit profiler tests pass
  • Verify flame chart renders correctly with real XHProf data
  • Switch between metrics (Wall time, CPU, Memory, Memory peak) and verify chart updates
  • Verify cached flame chart is per-metric (switching metric fetches fresh data)

🤖 Generated with Claude Code

PrepareEdges — rewrite parent resolution with two-pass approach:
- First pass creates all edges and builds a complete callee→edgeId map
- Second pass resolves parent references using the full map, eliminating
  the incorrect $prev fallback that linked edges to wrong parents when
  the caller function hadn't yet been processed
- BFS ordering ensures parents always precede children in edge order,
  which is required for correct tree construction in the flame chart
- Add ct to percentage calculation (p_ct was always 0)

FindFlameChartByUuidHandler — fix layout and metric handling:
- adjustStartTimes now clamps children within parent bounds: if the sum
  of children durations exceeds the parent, they are scaled down
  proportionally instead of overflowing the parent block
- Use metric-appropriate divisor (μs→ms for time, bytes→KB for memory)
- Parameterize metric via query (was hardcoded to wt)
- Include metric in cache file key to avoid stale cache across metrics

Add FlameChartRequest filter and wire metric through controller → query.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
butschster and others added 2 commits March 26, 2026 23:51
PreparePeaks now normalizes all profile entries by filling missing
metrics with 0 defaults before any downstream handler accesses them.
This fixes the ErrorException on CalculateDiffsBetweenEdges when cpu
key is absent, which happens in environments (e.g. DDEV) that disable
CPU profiling for performance.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@butschster butschster merged commit 00f2bb4 into master Mar 26, 2026
7 checks passed
@butschster butschster deleted the fix/profiler-flamechart branch March 26, 2026 20:26
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.

1 participant