PerformanceStatsEvent

Summary: ^

Reviewed By: aigoncharov

Differential Revision: D44062826

fbshipit-source-id: 3f66411a8648e635b75dfea29a6256e64cfbf5d5
This commit is contained in:
Lorenzo Blasa
2023-03-16 07:35:44 -07:00
committed by Facebook GitHub Bot
parent 5d0e0137d5
commit 76bfd67cd9
3 changed files with 34 additions and 31 deletions

View File

@@ -42,16 +42,16 @@ data class SubtreeUpdateEvent(
data class PerfStatsEvent( data class PerfStatsEvent(
val txId: Long, val txId: Long,
val observerType: String, val observerType: String,
val nodesCount: Int,
val start: Long, val start: Long,
val traversalComplete: Long, val traversalMS: Long,
val snapshotComplete: Long, val snapshotMS: Long,
val queuingComplete: Long, val queuingMS: Long,
val deferredComputationComplete: Long, val deferredComputationMS: Long,
val serializationComplete: Long, val serializationMS: Long,
val socketComplete: Long, val socketMS: Long
val nodesCount: Int
) { ) {
companion object { companion object {
const val name = "perfStats" const val name = "performanceStats"
} }
} }

View File

@@ -46,7 +46,7 @@ abstract class TreeObserver<T> {
snapshotBitmap: BitmapPool.ReusableBitmap? = null, snapshotBitmap: BitmapPool.ReusableBitmap? = null,
frameworkEvents: List<FrameworkEvent>? = null frameworkEvents: List<FrameworkEvent>? = null
) { ) {
val startTimestamp = System.currentTimeMillis() val traversalStartTimestamp = System.currentTimeMillis()
val (visitedNodes, observableRoots) = context.layoutTraversal.traverse(root) val (visitedNodes, observableRoots) = context.layoutTraversal.traverse(root)
// Add any new observers // Add any new observers
@@ -79,7 +79,7 @@ abstract class TreeObserver<T> {
} }
removables.forEach { key -> children.remove(key) } removables.forEach { key -> children.remove(key) }
val traversalCompleteTime = System.currentTimeMillis() val traversalEndTimestamp = System.currentTimeMillis()
if (snapshotBitmap != null) { if (snapshotBitmap != null) {
@Suppress("unchecked_cast") @Suppress("unchecked_cast")
@@ -89,16 +89,17 @@ abstract class TreeObserver<T> {
descriptor.getSnapshot(root, snapshotBitmap.bitmap) descriptor.getSnapshot(root, snapshotBitmap.bitmap)
} }
val snapshotCompleteTime = System.currentTimeMillis() val snapshotEndTimestamp = System.currentTimeMillis()
context.treeObserverManager.enqueueUpdate( context.treeObserverManager.enqueueUpdate(
SubtreeUpdate( SubtreeUpdate(
type, type,
root.objectIdentity(), root.objectIdentity(),
visitedNodes, visitedNodes,
startTimestamp, traversalStartTimestamp,
traversalCompleteTime, snapshotEndTimestamp,
snapshotCompleteTime, (traversalEndTimestamp - traversalStartTimestamp),
(snapshotEndTimestamp - traversalEndTimestamp),
frameworkEvents, frameworkEvents,
snapshotBitmap)) snapshotBitmap))
} }

View File

@@ -35,9 +35,10 @@ data class SubtreeUpdate(
val observerType: String, val observerType: String,
val rootId: Id, val rootId: Id,
val deferredNodes: List<MaybeDeferred<Node>>, val deferredNodes: List<MaybeDeferred<Node>>,
val startTime: Long, val timestamp: Long,
val traversalCompleteTime: Long, val queuedTimestamp: Long,
val snapshotComplete: Long, val traversalMS: Long,
val snapshotMS: Long,
val frameworkEvents: List<FrameworkEvent>?, val frameworkEvents: List<FrameworkEvent>?,
val snapshot: BitmapPool.ReusableBitmap? val snapshot: BitmapPool.ReusableBitmap?
) )
@@ -99,16 +100,16 @@ class TreeObserverManager(val context: UIDContext) {
} }
private fun sendBatchedUpdate(batchedUpdate: BatchedUpdate) { private fun sendBatchedUpdate(batchedUpdate: BatchedUpdate) {
Log.i( Log.i(
LogTag, LogTag,
"Got update from ${batchedUpdate.updates.size} observers at time ${batchedUpdate.frameTimeMs}") "Got update from ${batchedUpdate.updates.size} observers at time ${batchedUpdate.frameTimeMs}")
val onWorkerThread = 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 = batchedUpdate.updates.flatMap { it.frameworkEvents ?: listOf() }
val snapshotUpdate = batchedUpdate.updates.find { it.snapshot != null } val snapshotUpdate = batchedUpdate.updates.find { it.snapshot != null }
val deferredComptationComplete = System.currentTimeMillis() val deferredComputationEndTimestamp = System.currentTimeMillis()
var snapshot: String? = null var snapshot: String? = null
if (snapshotUpdate?.snapshot != null) { if (snapshotUpdate?.snapshot != null) {
@@ -134,25 +135,26 @@ class TreeObserverManager(val context: UIDContext) {
snapshot, snapshot,
frameworkEvents)) frameworkEvents))
val serializationEnd = System.currentTimeMillis() val serialisationEndTimestamp = System.currentTimeMillis()
context.connectionRef.connection?.send(SubtreeUpdateEvent.name, serialized) context.connectionRef.connection?.send(SubtreeUpdateEvent.name, serialized)
val socketEnd = System.currentTimeMillis() val socketEndTimestamp = System.currentTimeMillis()
Log.i(LogTag, "Sent event for batched subtree update with nodes with ${nodes.size}") Log.i(LogTag, "Sent event for batched subtree update with nodes with ${nodes.size}")
val perfStats = val perfStats =
PerfStatsEvent( PerfStatsEvent(
txId = batchedUpdate.frameTimeMs, txId = batchedUpdate.frameTimeMs,
observerType = "batched", observerType = "batched",
start = batchedUpdate.updates.minOf { it.startTime }, nodesCount = nodes.size,
traversalComplete = batchedUpdate.updates.maxOf { it.traversalCompleteTime }, start = batchedUpdate.updates.minOf { it.timestamp },
snapshotComplete = batchedUpdate.updates.maxOf { it.snapshotComplete }, traversalMS = batchedUpdate.updates.maxOf { it.traversalMS },
queuingComplete = onWorkerThread, snapshotMS = batchedUpdate.updates.maxOf { it.snapshotMS },
deferredComputationComplete = deferredComptationComplete, queuingMS =
serializationComplete = serializationEnd, workerThreadStartTimestamp - batchedUpdate.updates.minOf { it.queuedTimestamp },
socketComplete = socketEnd, deferredComputationMS = (deferredComputationEndTimestamp - workerThreadStartTimestamp),
nodesCount = nodes.size) serializationMS = (serialisationEndTimestamp - deferredComputationEndTimestamp),
socketMS = (socketEndTimestamp - serialisationEndTimestamp))
context.connectionRef.connection?.send( context.connectionRef.connection?.send(
PerfStatsEvent.name, Json.encodeToString(PerfStatsEvent.serializer(), perfStats)) PerfStatsEvent.name, Json.encodeToString(PerfStatsEvent.serializer(), perfStats))
@@ -168,7 +170,7 @@ class TreeObserverManager(val context: UIDContext) {
} }
} }
/** Buffers up subtree updates untill the frame is complete, should only be called on main thread */ /** Buffers up subtree updates until the frame is complete, should only be called on main thread */
private class SubtreeUpdateBuffer(private val onBatchReady: (BatchedUpdate) -> Unit) { private class SubtreeUpdateBuffer(private val onBatchReady: (BatchedUpdate) -> Unit) {
private val bufferedSubtreeUpdates = mutableListOf<SubtreeUpdate>() private val bufferedSubtreeUpdates = mutableListOf<SubtreeUpdate>()