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

Basic watchdog that triggers thread dumps on puck jank #2558

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jush
Copy link
Member

@jush jush commented Jan 10, 2025

Summary of changes

An example on how to extend a custom location provider to track puck animations jank.

Every time the puck is animated it starts a watchdog that will create a thread dump if the animation has not run for some milliseconds.
Capturing multiple thread dumps allows to detect if the main thread is stuck.

The gist of it is to add listeners to the animator and signal the watchdog (see LocationComponentAnimationActivity.listeners).
If enough time elapses (Watchdog.TIME_TO_FIRST_TRIGGER) without the watchdog being rescheduled (Watchdog.reschedule), then a thread dump will be written to disk (root permission is most likely needed to extract them). It continues to do so every 100 milliseconds (maximum 5 times) if reschedule is not yet called.
That way you could study the thread dumps and see what the main thread is doing.

NOTE: this is a simple implementation please study the code and adapt it better to your needs.

@@ -88,11 +116,20 @@ class LocationComponentAnimationActivity : AppCompatActivity() {
override fun registerLocationConsumer(locationConsumer: LocationConsumer) {
this.locationConsumer = locationConsumer
emitFakeLocations()
Watchdog.enabled = true
Copy link
Member Author

Choose a reason for hiding this comment

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

Before using the Watchdog you must enable it.

}

override fun unRegisterLocationConsumer(locationConsumer: LocationConsumer) {
this.locationConsumer = null
handler.removeCallbacksAndMessages(null)
Watchdog.enabled = false
Copy link
Member Author

Choose a reason for hiding this comment

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

Remember to disable it to stop its thread and free other resources.

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