[PLAT-6800] App hang detection improvements #1122
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
To prevent false positive detection of app hangs and improve performance.
Changeset
False positive mitigation
App hangs will now be ignored if the detector thread wakes up too long after the specified deadline. This condition could occur if an app was suspended while the detector thread was waiting on the (
processingFinished
) semaphore and subsequently woke up before the main thread was able to signal.The app hang deadline is now advanced whenever
kCFRunLoopBeforeSources
is encountered. This caters for cases where a busy run loop runs multiple timers / sources iteration before sleeping.Performance improvement
The detector has been reworked to use a long-lived thread controlled by signalling two semaphores. This is more efficient - profiling revealed that
dispatch_after
is roughly 7x slower thandispatch_semaphore_signal
.Other improvements
App hangs are now symbolicated in-app (this was broken by the recent change to symbolicate asynchronously)
Testing
Automated testing via E2E tests running the app hang scenarios.
Updated the example apps to include a fatal app hang sample.
Tested manually using example apps.