sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

feat(anr): Profile main thread when ANR and report ANR profiles to Sentry

Open markushi opened this issue 3 months ago • 2 comments

:scroll: Description

Adds ANR (Application Not Responding) profiling integration that profiles the main thread when an ANR is detected and reports the captured profiles to Sentry.

Key Changes:

  • New AnrProfilingIntegration to capture profiles during ANR events
  • AnrProfileManager to manage ANR profile lifecycle
  • AnrCulpritIdentifier to identify the culprit code causing ANR
  • Stack trace and profile aggregation utilities
  • Added comprehensive tests for ANR profiling functionality

:bulb: Motivation and Context

This feature enables better ANR diagnostics by capturing profiling data at the time of ANR detection, allowing developers to identify performance bottlenecks and problematic code paths causing application hangs.

:green_heart: How did you test it?

  • Unit tests for AnrCulpritIdentifier with various stack trace scenarios
  • Integration tests for AnrProfilingIntegration
  • Profile manager lifecycle tests
  • Stack trace converter tests

:pencil: Checklist

  • [ ] I added GH Issue ID & Linear ID
  • [x] I added tests to verify the changes.
  • [x] No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • [ ] I updated the docs if needed.
  • [ ] I updated the wizard if needed.
  • [ ] Review from the native team if needed.
  • [ ] No breaking change or entry added to the changelog.
  • [ ] No breaking change for hybrid SDKs or communicated to hybrid SDKs.

:crystal_ball: Next steps

markushi avatar Nov 12 '25 19:11 markushi

Messages
:book: Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by :no_entry_sign: dangerJS against 6c9acd74989d4bc1150294252bbab86e71241075

github-actions[bot] avatar Nov 12 '25 19:11 github-actions[bot]

Performance metrics :rocket:

  Plain With Sentry Diff
Startup time 331.24 ms 367.91 ms 36.67 ms
Size 1.58 MiB 2.13 MiB 563.53 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
5b66efdd143f1bca46f2a5b4a07c86cad63390b8 308.67 ms 363.85 ms 55.18 ms
fc5ccaf5844ae029d93c566b6fd1b4f5c2e4da83 322.49 ms 405.25 ms 82.76 ms
6405ec5190c8e1100237127feb4ba3d8a7e3fdba 310.88 ms 354.56 ms 43.69 ms
d364ace21d0a6c9f95548f5652560efd524e8349 382.77 ms 443.21 ms 60.44 ms
bbc35bb115c7c17672d4bef1fbec1a122307bbae 298.53 ms 372.17 ms 73.64 ms
3d205d0cc3fbcc85fbab1d74d6e2ab0930ddf031 352.15 ms 432.53 ms 80.38 ms
539ca63463fdf440a4e2c7f29c11fff348fe99fb 313.51 ms 355.43 ms 41.92 ms
dba088c465439af6142917dc884a1919ff042722 365.46 ms 366.31 ms 0.85 ms
fc5ccaf5844ae029d93c566b6fd1b4f5c2e4da83 270.49 ms 363.90 ms 93.41 ms
fcec2f233b744694bffee41e58e5a706e032ef51 328.91 ms 387.75 ms 58.84 ms

App size

Revision Plain With Sentry Diff
5b66efdd143f1bca46f2a5b4a07c86cad63390b8 1.58 MiB 2.13 MiB 559.07 KiB
fc5ccaf5844ae029d93c566b6fd1b4f5c2e4da83 1.58 MiB 2.13 MiB 557.54 KiB
6405ec5190c8e1100237127feb4ba3d8a7e3fdba 1.58 MiB 2.12 MiB 552.23 KiB
d364ace21d0a6c9f95548f5652560efd524e8349 1.58 MiB 2.11 MiB 539.75 KiB
bbc35bb115c7c17672d4bef1fbec1a122307bbae 1.58 MiB 2.12 MiB 553.01 KiB
3d205d0cc3fbcc85fbab1d74d6e2ab0930ddf031 1.58 MiB 2.10 MiB 532.97 KiB
539ca63463fdf440a4e2c7f29c11fff348fe99fb 1.58 MiB 2.12 MiB 551.41 KiB
dba088c465439af6142917dc884a1919ff042722 1.58 MiB 2.13 MiB 558.99 KiB
fc5ccaf5844ae029d93c566b6fd1b4f5c2e4da83 1.58 MiB 2.13 MiB 557.54 KiB
fcec2f233b744694bffee41e58e5a706e032ef51 1.58 MiB 2.12 MiB 551.50 KiB

Previous results on branch: markushi/feat/anr-profiling

Startup times

Revision Plain With Sentry Diff
a4af52ffafdf5f6f6b49cd88a4e5f4604bf5a294 304.52 ms 364.92 ms 60.40 ms
be4960b91cd348f85ae199797fb629bff7edc091 322.67 ms 380.85 ms 58.18 ms
184b846e4c98f806cbb1f0b4e8b973af63b05d9c 276.09 ms 351.65 ms 75.56 ms
b238cfff4195f4914ef4347cf732c67563a366d4 332.00 ms 401.47 ms 69.47 ms

App size

Revision Plain With Sentry Diff
a4af52ffafdf5f6f6b49cd88a4e5f4604bf5a294 1.58 MiB 2.13 MiB 563.53 KiB
be4960b91cd348f85ae199797fb629bff7edc091 1.58 MiB 2.13 MiB 562.64 KiB
184b846e4c98f806cbb1f0b4e8b973af63b05d9c 1.58 MiB 2.13 MiB 558.70 KiB
b238cfff4195f4914ef4347cf732c67563a366d4 1.58 MiB 2.13 MiB 562.66 KiB

github-actions[bot] avatar Nov 12 '25 19:11 github-actions[bot]

@sentry review

markushi avatar Dec 17 '25 08:12 markushi