Skip to content

Commit

Permalink
Add connection listeners and framework events
Browse files Browse the repository at this point in the history
Summary: Infra that will be used to capture litho framework events

Reviewed By: lblasa

Differential Revision: D47951601

fbshipit-source-id: 1dd756dc872d474f2872ff8cac1fd6aa3697e42b
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed Aug 8, 2023
1 parent 0fdd901 commit b30f749
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class UIDebuggerFlipperPlugin(val context: UIDContext) : FlipperPlugin {
MetadataUpdateEvent(MetadataRegister.extractPendingMetadata())))

context.treeObserverManager.start()

context.connectionListeners.forEach { it.onConnect() }
}

@Throws(Exception::class)
Expand All @@ -59,6 +61,8 @@ class UIDebuggerFlipperPlugin(val context: UIDContext) : FlipperPlugin {

context.treeObserverManager.stop()
context.bitmapPool.recycleAll()
context.connectionListeners.forEach { it.onDisconnect() }
context.clearFrameworkEvents()
}

override fun runInBackground(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,62 @@ import android.app.Application
import com.facebook.flipper.core.FlipperConnection
import com.facebook.flipper.plugins.uidebugger.common.BitmapPool
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.observers.TreeObserverFactory
import com.facebook.flipper.plugins.uidebugger.observers.TreeObserverManager
import com.facebook.flipper.plugins.uidebugger.scheduler.SharedThrottle
import com.facebook.flipper.plugins.uidebugger.traversal.PartialLayoutTraversal

data class UIDContext(
interface ConnectionListener {
fun onConnect()

fun onDisconnect()
}

class UIDContext(
val applicationRef: ApplicationRef,
val connectionRef: ConnectionRef,
val descriptorRegister: DescriptorRegister,
val observerFactory: TreeObserverFactory,
val frameworkEventMetadata: MutableList<FrameworkEventMetadata>
val frameworkEventMetadata: MutableList<FrameworkEventMetadata>,
val connectionListeners: MutableList<ConnectionListener>,
private val pendingFrameworkEvents: MutableList<FrameworkEvent>
) {

val layoutTraversal: PartialLayoutTraversal =
PartialLayoutTraversal(descriptorRegister, observerFactory)

val treeObserverManager = TreeObserverManager(this)
val sharedThrottle: SharedThrottle = SharedThrottle()
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 {
fun create(application: Application): UIDContext {
return UIDContext(
ApplicationRef(application),
ConnectionRef(null),
descriptorRegister = DescriptorRegister.withDefaults(),
observerFactory = TreeObserverFactory.withDefaults(),
frameworkEventMetadata = mutableListOf())
frameworkEventMetadata = mutableListOf(),
connectionListeners = mutableListOf(),
pendingFrameworkEvents = mutableListOf())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ data class FrameworkEvent(
val nodeId: Id,
val type: String,
val timestamp: Long,
val thread: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class TreeObserverManager(val context: UIDContext) {
val workerThreadStartTimestamp = System.currentTimeMillis()

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 deferredComputationEndTimestamp = System.currentTimeMillis()

Expand Down

0 comments on commit b30f749

Please sign in to comment.