Skip to content

feat(flamegraph): Identify MetricKit hang culprit stacks in Relay - #6520

Open
philprime wants to merge 3 commits into
philprime/feat/flamegraph-attachmentsfrom
philprime/feat/flamegraph-culprit-identification
Open

philprime wants to merge 3 commits into
philprime/feat/flamegraph-attachmentsfrom
philprime/feat/flamegraph-culprit-identification

Conversation

@philprime

Copy link
Copy Markdown
Member

Culprit identification belongs in Relay so we can share it across SDKs instead of implementing and maintaining the same selection algorithm in each SDK. SDKs can send sampled call trees, while Relay derives a representative exception stack for normal symbolication and grouping. This PR establishes that shared implementation, with MetricKit hangs as its first consumer.

Stacked on #6473. The base branch is philprime/feat/flamegraph-attachments, so this diff contains only culprit selection and event enrichment.

Selection and integration

The selector follows Android's AnrCulpritIdentifier scoring: sample_count × (depth + application_frames). It folds identical root-to-frame prefixes using inclusive sample counts, keeps independent tree populations separate, prefers attributed trees, and resolves ties in input order. Application weighting uses supplied in_app values rather than platform-specific package rules.

Only mx_hang_diagnostic events are enriched in this PR. Processing Relays fill missing exception stacks before normalization, allowing derived frames to follow the existing trimming, filtering, and PII-scrubbing pipeline. Existing stacks remain authoritative. The complete attachment stays unchanged, while only debug images needed by the selected path are copied into the event, with relative references remapped to avoid collisions with existing event images.

Other SDKs can reuse the selector when they adopt the attachment format. This PR does not enable Android ANR enrichment or change any SDK.

Validation

The implementation was AI-assisted. make check and make test passed, including the all-feature Rust workspace tests, Python tests, and full integration suite. Focused coverage exercises prefix scoring, duplicate frames, recursion, large counts, debug-image selection/remapping, and processing versus forwarding behavior.

@linear-code

linear-code Bot commented Oct 16, 2026

Copy link
Copy Markdown

COCOA-2078

@philprime philprime self-assigned this Oct 16, 2026
@philprime
philprime marked this pull request as ready for review October 16, 2026 09:40
@philprime
philprime requested a review from a team as a code owner October 16, 2026 09:40
@philprime
philprime requested review from markushi and romtsn October 16, 2026 09:48
Index diagnostic images by address and debug ID to avoid per-frame scans.

Bound derived frame data before materializing recursive call paths.
@philprime
philprime force-pushed the philprime/feat/flamegraph-culprit-identification branch from cabb3a0 to 2f95ff1 Compare October 16, 2026 13:20

This branch has not been deployed

No deployments
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