Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't use main thread for app hang screenshot and view hierarchy #3547

Merged
merged 10 commits into from
Feb 2, 2024

Conversation

brustolin
Copy link
Contributor

📜 Description

During an app hang event, we attempt to capture a screenshot and view hierarchy in the main thread. However, the main thread is blocked, so the event must wait for the main thread to be freed, a situation that may never occur.

💡 Motivation and Context

Close #3220

💚 How did you test it?

Unit Test

📝 Checklist

You have to check all boxes before merging:

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs 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.

🔮 Next steps

Copy link

github-actions bot commented Jan 5, 2024

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1226.92 ms 1249.82 ms 22.90 ms
Size 21.58 KiB 418.70 KiB 397.11 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
1437c68 1244.86 ms 1254.18 ms 9.32 ms
7c5d161 1224.38 ms 1249.66 ms 25.28 ms
6001822 1202.61 ms 1213.50 ms 10.89 ms
257c2a9 1239.52 ms 1251.08 ms 11.56 ms
2af280d 1246.22 ms 1253.10 ms 6.88 ms
ecd9ecd 1191.76 ms 1216.92 ms 25.16 ms
ad7cec6 1203.22 ms 1224.74 ms 21.52 ms
01a28a9 1237.78 ms 1259.04 ms 21.27 ms
a176fc4 1226.24 ms 1247.50 ms 21.26 ms
98752f3 1240.61 ms 1259.80 ms 19.18 ms

App size

Revision Plain With Sentry Diff
1437c68 22.85 KiB 410.96 KiB 388.11 KiB
7c5d161 20.76 KiB 414.44 KiB 393.68 KiB
6001822 22.85 KiB 410.98 KiB 388.13 KiB
257c2a9 20.76 KiB 401.36 KiB 380.60 KiB
2af280d 20.76 KiB 435.22 KiB 414.46 KiB
ecd9ecd 20.76 KiB 420.23 KiB 399.47 KiB
ad7cec6 20.76 KiB 427.32 KiB 406.55 KiB
01a28a9 22.85 KiB 405.39 KiB 382.54 KiB
a176fc4 22.84 KiB 403.24 KiB 380.39 KiB
98752f3 20.76 KiB 435.09 KiB 414.33 KiB

Previous results on branch: fix/screenshot-anr

Startup times

Revision Plain With Sentry Diff
0a8b53c 1204.04 ms 1214.56 ms 10.52 ms
5d91312 1199.92 ms 1211.47 ms 11.55 ms
0f7cf35 1222.74 ms 1244.75 ms 22.01 ms

App size

Revision Plain With Sentry Diff
0a8b53c 21.58 KiB 418.49 KiB 396.91 KiB
5d91312 21.58 KiB 419.20 KiB 397.61 KiB
0f7cf35 21.58 KiB 419.16 KiB 397.57 KiB

Copy link

codecov bot commented Jan 5, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (1c96132) 89.289% compared to head (78d91d8) 89.327%.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #3547       +/-   ##
=============================================
+ Coverage   89.289%   89.327%   +0.037%     
=============================================
  Files          529       529               
  Lines        57737     57979      +242     
  Branches     20412     20740      +328     
=============================================
+ Hits         51553     51791      +238     
  Misses        5276      5276               
- Partials       908       912        +4     
Files Coverage Δ
Sources/Sentry/SentryANRTrackingIntegration.m 95.918% <100.000%> (ø)
Sources/Sentry/SentryEvent.m 98.518% <100.000%> (+0.045%) ⬆️
Sources/Sentry/SentryScreenshotIntegration.m 91.836% <100.000%> (+1.139%) ⬆️
Sources/Sentry/SentryViewHierarchy.m 98.979% <100.000%> (-0.011%) ⬇️
Sources/Sentry/SentryViewHierarchyIntegration.m 100.000% <100.000%> (ø)
...ations/ANR/SentryANRTrackingIntegrationTests.swift 94.339% <100.000%> (+1.436%) ⬆️
.../Screenshot/SentryScreenshotIntegrationTests.swift 99.382% <100.000%> (+0.091%) ⬆️
...Integrations/Screenshot/TestSentryScreenShot.swift 100.000% <100.000%> (ø)
...ierarchy/SentryViewHierarchyIntegrationTests.swift 99.159% <100.000%> (+0.190%) ⬆️
...ations/ViewHierarchy/TestSentryViewHierarchy.swift 100.000% <100.000%> (ø)
... and 4 more

... and 73 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c96132...78d91d8. Read the comment docs.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Thanks for doing this. A couple of comments.

Sources/Sentry/SentryANRTracker.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryANRTracker.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryANRTracker.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryScreenshotIntegration.m Outdated Show resolved Hide resolved
Sources/Sentry/include/SentryANRTracker.h Outdated Show resolved Hide resolved
Sources/Sentry/include/SentryViewHierarchy.h Outdated Show resolved Hide resolved
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Almost, LGTM.

Sources/Sentry/SentryEvent.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryEvent.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryEvent.m Outdated Show resolved Hide resolved
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @brustolin 💪

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Again, LGTM.

@brustolin brustolin merged commit 236d8a8 into main Feb 2, 2024
69 of 71 checks passed
@brustolin brustolin deleted the fix/screenshot-anr branch February 2, 2024 08:13
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.

Don't use the main thread for screenshots/view hierarch during App hangs.
3 participants