-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add heapDumpDurationMillis to HeapAnalysis #1931
Conversation
@@ -65,12 +65,14 @@ internal class AndroidHeapDumper( | |||
val toast = waitingForToast.get() | |||
|
|||
return try { | |||
Debug.dumpHprofData(heapDumpFile.absolutePath) | |||
val durationMillis = measureTimeMillis { |
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.
measureTimeMillis is based on System.currentTimeMillis() which isn't recommended for measuring durations (not monotonically increasing).
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.
Good point. I have switched to a new util method which calls SystemClock.uptimeMillis()
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.
leakcanary-android-core/src/main/java/leakcanary/internal/AndroidHeapDumper.kt
Outdated
Show resolved
Hide resolved
leakcanary-android-core/src/main/java/leakcanary/internal/HeapAnalyzerService.kt
Outdated
Show resolved
Hide resolved
leakcanary-android-core/src/main/java/leakcanary/internal/HeapAnalyzerService.kt
Outdated
Show resolved
Hide resolved
leakcanary-android-core/src/main/java/leakcanary/internal/HeapAnalyzerService.kt
Outdated
Show resolved
Hide resolved
leakcanary-android-core/src/main/java/leakcanary/internal/HeapDumpTrigger.kt
Outdated
Show resolved
Hide resolved
leakcanary-android-core/src/main/java/leakcanary/internal/HeapDumper.kt
Outdated
Show resolved
Hide resolved
462399d
to
61e1a47
Compare
On Android 11, we have experienced slow heap dumps as described in https://issuetracker.google.com/issues/168634429.
The heap dump was still relatively quick for a vanilla sampe project, so I would like to contribute to leak canary to verify the heap dump in a large-scale app to support the arguments.
Implementation-wise, I used -1 as an invalid duration and the corresponding formatted text would be "UNKNOWN". If the duration for the heap dump is valid, the text would be like "42 ms".
I have tested this patch manually by installing on my device as well as running
./gradlew test
. If there are other steps I need to take for testing, please let me know.