LogcatEventListener.kt
TLDR
The LogcatEventListener.kt
file is used in the LeakCanary library as an event listener. It listens for events related to heap analysis and heap dumps, and logs information to the logcat.
Methods
None.
Classes
None.
package leakcanary
import leakcanary.EventListener.Event
import leakcanary.EventListener.Event.HeapAnalysisDone
import leakcanary.EventListener.Event.HeapAnalysisProgress
import leakcanary.EventListener.Event.HeapDumpFailed
import leakcanary.internal.HeapDumpTrigger
import leakcanary.internal.activity.screen.LeakTraceWrapper
import shark.SharkLog
object LogcatEventListener : EventListener {
override fun onEvent(event: Event) {
when(event) {
is HeapDumpFailed -> {
if (event.willRetryLater) {
SharkLog.d(event.exception) { "Failed to dump heap, will retry in ${HeapDumpTrigger.WAIT_AFTER_DUMP_FAILED_MILLIS} ms" }
} else {
SharkLog.d(event.exception) { "Failed to dump heap, will not automatically retry" }
}
}
is HeapAnalysisProgress -> {
val percent = (event.progressPercent * 100).toInt()
SharkLog.d { "Analysis in progress, $percent% done, working on ${event.step.humanReadableName}" }
}
is HeapAnalysisDone<*> -> {
SharkLog.d { "\u200B\n${LeakTraceWrapper.wrap(event.heapAnalysis.toString(), 120)}" }
}
else -> {}
}
}
}