Repository navigation
fix(anr): Skip ANR profiling while a debugger is connected #6389
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion; | ||
|
|
||
| import android.os.Debug; | ||
| import android.os.Handler; | ||
| import android.os.Looper; | ||
| import android.os.SystemClock; | ||
|
|
@@ -211,6 +212,15 @@ public void run() { | |
|
|
||
| @ApiStatus.Internal | ||
| protected void checkMainThread(final @NotNull Thread mainThread) throws IOException { | ||
| if (isDebuggerConnected()) { | ||
| // The main thread can sit at a breakpoint for a long time, which is not an ANR. Reset the | ||
| // timestamp, so the paused time does not count against us after the debugger detaches. | ||
| mainThreadState = MainThreadState.IDLE; | ||
| sampled = false; | ||
| updater.run(); | ||
| return; | ||
| } | ||
|
|
||
| final long now = SystemClock.uptimeMillis(); | ||
| final long diff = now - lastMainThreadExecutionTime; | ||
|
|
||
|
|
@@ -268,6 +278,11 @@ protected void checkMainThread(final @NotNull Thread mainThread) throws IOExcept | |
| } | ||
| } | ||
|
|
||
| @ApiStatus.Internal | ||
| protected boolean isDebuggerConnected() { | ||
| return Debug.isDebuggerConnected(); | ||
|
markushi marked this conversation as resolved.
Resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. separately, it seems to me this is protected only so that we can override this for testing. if that's the case, can we instead wrap
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah exactly, my clanker came up with this, I guess in order to avoid any breaking API changes in the ctor. First I thought it's elegant, as it saves the extra interface definitions and constructor overloads. But the more I think about it the more disadvantages I see, let me change that! |
||
| } | ||
|
|
||
| @TestOnly | ||
| @NotNull | ||
| protected MainThreadState getState() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Before returning, should we also call
clearStacks()if we've collected any?