Add connection listeners and framework events
Summary: Infra that will be used to capture litho framework events Reviewed By: lblasa Differential Revision: D47951601 fbshipit-source-id: 1dd756dc872d474f2872ff8cac1fd6aa3697e42b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0fdd901297
commit
b30f7492cd
@@ -49,6 +49,8 @@ class UIDebuggerFlipperPlugin(val context: UIDContext) : FlipperPlugin {
|
|||||||
MetadataUpdateEvent(MetadataRegister.extractPendingMetadata())))
|
MetadataUpdateEvent(MetadataRegister.extractPendingMetadata())))
|
||||||
|
|
||||||
context.treeObserverManager.start()
|
context.treeObserverManager.start()
|
||||||
|
|
||||||
|
context.connectionListeners.forEach { it.onConnect() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
@@ -59,6 +61,8 @@ class UIDebuggerFlipperPlugin(val context: UIDContext) : FlipperPlugin {
|
|||||||
|
|
||||||
context.treeObserverManager.stop()
|
context.treeObserverManager.stop()
|
||||||
context.bitmapPool.recycleAll()
|
context.bitmapPool.recycleAll()
|
||||||
|
context.connectionListeners.forEach { it.onDisconnect() }
|
||||||
|
context.clearFrameworkEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun runInBackground(): Boolean {
|
override fun runInBackground(): Boolean {
|
||||||
|
|||||||
@@ -11,19 +11,29 @@ import android.app.Application
|
|||||||
import com.facebook.flipper.core.FlipperConnection
|
import com.facebook.flipper.core.FlipperConnection
|
||||||
import com.facebook.flipper.plugins.uidebugger.common.BitmapPool
|
import com.facebook.flipper.plugins.uidebugger.common.BitmapPool
|
||||||
import com.facebook.flipper.plugins.uidebugger.descriptors.DescriptorRegister
|
import com.facebook.flipper.plugins.uidebugger.descriptors.DescriptorRegister
|
||||||
|
import com.facebook.flipper.plugins.uidebugger.model.FrameworkEvent
|
||||||
import com.facebook.flipper.plugins.uidebugger.model.FrameworkEventMetadata
|
import com.facebook.flipper.plugins.uidebugger.model.FrameworkEventMetadata
|
||||||
import com.facebook.flipper.plugins.uidebugger.observers.TreeObserverFactory
|
import com.facebook.flipper.plugins.uidebugger.observers.TreeObserverFactory
|
||||||
import com.facebook.flipper.plugins.uidebugger.observers.TreeObserverManager
|
import com.facebook.flipper.plugins.uidebugger.observers.TreeObserverManager
|
||||||
import com.facebook.flipper.plugins.uidebugger.scheduler.SharedThrottle
|
import com.facebook.flipper.plugins.uidebugger.scheduler.SharedThrottle
|
||||||
import com.facebook.flipper.plugins.uidebugger.traversal.PartialLayoutTraversal
|
import com.facebook.flipper.plugins.uidebugger.traversal.PartialLayoutTraversal
|
||||||
|
|
||||||
data class UIDContext(
|
interface ConnectionListener {
|
||||||
|
fun onConnect()
|
||||||
|
|
||||||
|
fun onDisconnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
class UIDContext(
|
||||||
val applicationRef: ApplicationRef,
|
val applicationRef: ApplicationRef,
|
||||||
val connectionRef: ConnectionRef,
|
val connectionRef: ConnectionRef,
|
||||||
val descriptorRegister: DescriptorRegister,
|
val descriptorRegister: DescriptorRegister,
|
||||||
val observerFactory: TreeObserverFactory,
|
val observerFactory: TreeObserverFactory,
|
||||||
val frameworkEventMetadata: MutableList<FrameworkEventMetadata>
|
val frameworkEventMetadata: MutableList<FrameworkEventMetadata>,
|
||||||
|
val connectionListeners: MutableList<ConnectionListener>,
|
||||||
|
private val pendingFrameworkEvents: MutableList<FrameworkEvent>
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val layoutTraversal: PartialLayoutTraversal =
|
val layoutTraversal: PartialLayoutTraversal =
|
||||||
PartialLayoutTraversal(descriptorRegister, observerFactory)
|
PartialLayoutTraversal(descriptorRegister, observerFactory)
|
||||||
|
|
||||||
@@ -31,6 +41,22 @@ data class UIDContext(
|
|||||||
val sharedThrottle: SharedThrottle = SharedThrottle()
|
val sharedThrottle: SharedThrottle = SharedThrottle()
|
||||||
val bitmapPool = BitmapPool()
|
val bitmapPool = BitmapPool()
|
||||||
|
|
||||||
|
fun addFrameworkEvent(frameworkEvent: FrameworkEvent) {
|
||||||
|
synchronized(pendingFrameworkEvents) { pendingFrameworkEvents.add(frameworkEvent) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun extractPendingFrameworkEvents(): List<FrameworkEvent> {
|
||||||
|
synchronized(pendingFrameworkEvents) {
|
||||||
|
val copy = pendingFrameworkEvents.toList()
|
||||||
|
pendingFrameworkEvents.clear()
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearFrameworkEvents() {
|
||||||
|
synchronized(pendingFrameworkEvents) { pendingFrameworkEvents.clear() }
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun create(application: Application): UIDContext {
|
fun create(application: Application): UIDContext {
|
||||||
return UIDContext(
|
return UIDContext(
|
||||||
@@ -38,7 +64,9 @@ data class UIDContext(
|
|||||||
ConnectionRef(null),
|
ConnectionRef(null),
|
||||||
descriptorRegister = DescriptorRegister.withDefaults(),
|
descriptorRegister = DescriptorRegister.withDefaults(),
|
||||||
observerFactory = TreeObserverFactory.withDefaults(),
|
observerFactory = TreeObserverFactory.withDefaults(),
|
||||||
frameworkEventMetadata = mutableListOf())
|
frameworkEventMetadata = mutableListOf(),
|
||||||
|
connectionListeners = mutableListOf(),
|
||||||
|
pendingFrameworkEvents = mutableListOf())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,4 +20,5 @@ data class FrameworkEvent(
|
|||||||
val nodeId: Id,
|
val nodeId: Id,
|
||||||
val type: String,
|
val type: String,
|
||||||
val timestamp: Long,
|
val timestamp: Long,
|
||||||
|
val thread: String
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class TreeObserverManager(val context: UIDContext) {
|
|||||||
val workerThreadStartTimestamp = System.currentTimeMillis()
|
val workerThreadStartTimestamp = System.currentTimeMillis()
|
||||||
|
|
||||||
val nodes = batchedUpdate.updates.flatMap { it.deferredNodes.map { it.value() } }
|
val nodes = batchedUpdate.updates.flatMap { it.deferredNodes.map { it.value() } }
|
||||||
val frameworkEvents = batchedUpdate.updates.flatMap { it.frameworkEvents ?: listOf() }
|
val frameworkEvents = context.extractPendingFrameworkEvents()
|
||||||
val snapshotUpdate = batchedUpdate.updates.find { it.snapshot != null }
|
val snapshotUpdate = batchedUpdate.updates.find { it.snapshot != null }
|
||||||
val deferredComputationEndTimestamp = System.currentTimeMillis()
|
val deferredComputationEndTimestamp = System.currentTimeMillis()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user