Skip to content

Commit a1c1d21

Browse files
Fabio Carballofacebook-github-bot
Fabio Carballo
authored andcommitted
Add SynchronousStateUpdate event
Summary: Adding a DebugEvent for Sync State Updates Reviewed By: adityasharat Differential Revision: D44429123 fbshipit-source-id: 1a23df0b9847770df5d99699e23cca8d30bb3c15
1 parent 2f9a2e9 commit a1c1d21

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

litho-core/src/main/java/com/facebook/litho/ComponentTree.java

+21
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@
7070
import com.facebook.litho.config.ComponentsConfiguration;
7171
import com.facebook.litho.config.ResolveCancellationStrategy;
7272
import com.facebook.litho.debug.LithoDebugEvent;
73+
import com.facebook.litho.debug.LithoDebugEventAttributes;
7374
import com.facebook.litho.perfboost.LithoPerfBooster;
7475
import com.facebook.litho.stats.LithoStats;
7576
import com.facebook.rendercore.RunnableHandler;
7677
import com.facebook.rendercore.RunnableHandler.DefaultHandler;
7778
import com.facebook.rendercore.debug.DebugEventAttribute;
79+
import com.facebook.rendercore.debug.DebugEventBus;
7880
import com.facebook.rendercore.debug.DebugEventDispatcher;
7981
import com.facebook.rendercore.visibility.VisibilityBoundsTransformer;
8082
import java.lang.ref.WeakReference;
@@ -1432,6 +1434,8 @@ public final void updateHookStateAsync(
14321434
}
14331435

14341436
private void onAsyncStateUpdateEnqueued(String attribution, boolean isCreateLayoutInProgress) {
1437+
dispatchStateUpdateEnqueuedEvent(attribution, false);
1438+
14351439
if (mBatchedStateUpdatesStrategy == null
14361440
|| !mBatchedStateUpdatesStrategy.onAsyncStateUpdateEnqueued(
14371441
attribution, isCreateLayoutInProgress)) {
@@ -1472,6 +1476,8 @@ private void ensureSyncStateUpdateRunnable(String attribution, boolean isCreateL
14721476
sSyncStateUpdatesHandler.set(new WeakReference<>(handler));
14731477
}
14741478

1479+
dispatchStateUpdateEnqueuedEvent(attribution, true);
1480+
14751481
synchronized (mUpdateStateSyncRunnableLock) {
14761482
if (mUpdateStateSyncRunnable != null) {
14771483
handler.remove(mUpdateStateSyncRunnable);
@@ -1486,6 +1492,21 @@ private void ensureSyncStateUpdateRunnable(String attribution, boolean isCreateL
14861492
}
14871493
}
14881494

1495+
private void dispatchStateUpdateEnqueuedEvent(String attribution, boolean isSynchronous) {
1496+
if (DebugEventBus.getEnabled()) {
1497+
DebugEventDispatcher.dispatch(
1498+
LithoDebugEvent.StateUpdateEnqueued,
1499+
String.valueOf(mId),
1500+
() -> {
1501+
HashMap<String, Object> map = new HashMap<>();
1502+
map.put(LithoDebugEventAttributes.Root, mRoot != null ? mRoot.getSimpleName() : "");
1503+
map.put(LithoDebugEventAttributes.Attribution, attribution);
1504+
map.put(LithoDebugEventAttributes.StateUpdateType, isSynchronous ? "sync" : "async");
1505+
return map;
1506+
});
1507+
}
1508+
}
1509+
14891510
void updateStateInternal(boolean isAsync, String attribution, boolean isCreateLayoutInProgress) {
14901511
final @Nullable TreeProps rootTreeProps;
14911512

litho-core/src/main/java/com/facebook/litho/debug/LithoDebugEvent.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ object LithoDebugEvent {
2222
val RenderCore: DebugEvent.Companion = DebugEvent
2323
const val LayoutCommitted = "Litho.LayoutCommitted"
2424
const val LayoutCalculated = "Litho.LayoutCalculated"
25-
const val MeasureSizeSpecsMismatch = "SizeSpecsMismatch"
25+
const val MeasureSizeSpecsMismatch = "Litho.SizeSpecsMismatch"
26+
const val StateUpdateEnqueued = "Litho.StateUpdateEnqueued"
2627
}
2728

2829
object LithoDebugEventAttributes {
2930

3031
const val Root = "root"
32+
const val Attribution = "attribution"
33+
const val StateUpdateType = "state_update_type"
3134
const val MainThreadLayoutStateWidthSpec = "main_thread_layout_state_width_spec"
3235
const val MainThreadLayoutStateHeightSpec = "main_thread_layout_state_height_spec"
3336
const val MeasureWidthSpec = "measure_width_spec"

0 commit comments

Comments
 (0)