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
LeakCanary 3 #2511
Labels
Milestone
Comments
Conversation on coroutines / flow for LeakTracer with Bill: package shark
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.SharedFlow
import shark.LeakTracer.TraceObjectsEvent.StartedBuildingLeakTraces
fun interface LeakTracer {
// TODO What should we do about exceptions here? union error or exception?
fun traceObjects(objectIds: Set<Long>): LeaksAndUnreachableObjects
// main safety
suspend fun traceObjectsSuspending(
// coroutineContext: CoroutineDispatcher, // this doesn't allow me to say, "use my existing dispatcher!"
coroutineContext: CoroutineContext, // constructor DI is probably a good approach for this
// Be careful with context you call this on!
// * events callback should be called on the same CoroutineContext as traceObjectsSuspending
// Also: make sure and honor exception contracts! (e.g. if `events` throws,
// `traceObjectSuspending` should throw that exeption)
//
// Flows get the above invariants right, so if you build on top of them you should be good
events: (TraceObjectsEvent)->Unit
): LeaksAndUnreachableObjects
data class TraceObjectsAsyncProcess(
val job: Job,
val events: SharedFlow<TraceObjectsEvent>,
val result: Deferred<LeaksAndUnreachableObjects>,
)
fun traceObjectsAsync(coroutineScope: CoroutineScope, objectIds: Set<Long>): TraceObjectsAsyncProcess
suspend fun heapGraph(block: suspend HeapGraph.()->Unit)
suspend fun blah () {
coroutineScope {
val result: Deferred<Int> = async {
1
}
}
val result = traceObjectsSuspending {
// event handling here
}
}
// Flow? AndroidX Biometrics API
//
sealed interface TraceObjectsEvent {
object StartedBuildingLeakTraces : TraceObjectsEvent
object StartedInspectingObjects : TraceObjectsEvent
object StartedComputingNativeRetainedSize: TraceObjectsEvent
object StartedComputingJavaHeapRetainedSize: TraceObjectsEvent
}
fun traceObjectsFlow(objectIds: Set<Long>) : Flow<TraceObjectsEvent>
// what this ^^^^ is actually doing
suspend fun myFunction(callback: suspend (TraceObjectsEvent)->Unit) {
while (true) {
callback(StartedBuildingLeakTraces)
}
}
fun whatItIsDoing() = object : Flow<TraceObjectsEvent> {
override suspend fun collect(collector: FlowCollector<TraceObjectsEvent>) {
TODO("Not yet implemented")
}
}
fun interface Factory {
fun createFor(heapGraph: HeapGraph): LeakTracer
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What to expect.
Changes to configuration
Startup
Analysis now performed in LeakCanary app
App APIs
New features
Notifications
Security
Analytics
Proguard / R8
Installing / upgrading the app
App internals
Dependency updates
Removed old LeakCanary activity
Internals and APIs
Compose Desktop / Intellij Plugin
New feature
The text was updated successfully, but these errors were encountered: