From e773b36990089ac242ada89e26b7fa2803e3c13a Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 14 Jun 2018 18:36:32 -0700 Subject: [PATCH] Refactor Log to Flog in Fabric Reviewed By: shergin Differential Revision: D8363593 fbshipit-source-id: fb4104b66ef3d50d4101c39a1bf4515e6d0ecd19 --- .../debug/tags/ReactDebugOverlayTags.java | 10 +++++ .../react/bridge/PerformanceCounter.java | 2 +- .../main/java/com/facebook/react/fabric/BUCK | 3 ++ .../react/fabric/FabricReconciler.java | 12 ++++-- .../react/fabric/FabricUIManager.java | 40 ++++++++++--------- .../java/com/facebook/react/uimanager/BUCK | 1 + .../react/uimanager/ReactShadowNodeImpl.java | 9 +++-- 7 files changed, 51 insertions(+), 26 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/debug/tags/ReactDebugOverlayTags.java b/ReactAndroid/src/main/java/com/facebook/debug/tags/ReactDebugOverlayTags.java index 6bc6b5983..879743ce9 100644 --- a/ReactAndroid/src/main/java/com/facebook/debug/tags/ReactDebugOverlayTags.java +++ b/ReactAndroid/src/main/java/com/facebook/debug/tags/ReactDebugOverlayTags.java @@ -27,6 +27,16 @@ public class ReactDebugOverlayTags { "UI Manager", "UI Manager View Operations (requires restart\nwarning: this is spammy)", Color.CYAN); + public static final DebugOverlayTag FABRIC_UI_MANAGER = + new DebugOverlayTag( + "FabricUIManager", + "Fabric UI Manager View Operations", + Color.CYAN); + public static final DebugOverlayTag FABRIC_RECONCILER = + new DebugOverlayTag( + "FabricReconciler", + "Reconciler for Fabric", + Color.CYAN); public static final DebugOverlayTag RELAY = new DebugOverlayTag("Relay", "including prefetching", Color.rgb(0xFF, 0x99, 0x00)); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/PerformanceCounter.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/PerformanceCounter.java index b4a075ae6..7acd416a9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/PerformanceCounter.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/PerformanceCounter.java @@ -9,5 +9,5 @@ package com.facebook.react.bridge; import java.util.Map; public interface PerformanceCounter { - public Map getPerformanceCounters(); + Map getPerformanceCounters(); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/BUCK b/ReactAndroid/src/main/java/com/facebook/react/fabric/BUCK index d4d239f3d..88dfe4bd5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/BUCK @@ -15,9 +15,12 @@ rn_android_library( ], deps = [ YOGA_TARGET, + react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"), react_native_dep("third-party/java/infer-annotations:infer-annotations"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_target("java/com/facebook/react:react"), + react_native_target("java/com/facebook/debug/tags:tags"), + react_native_target("java/com/facebook/debug/holder:holder"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricReconciler.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricReconciler.java index c42de9efe..ba8b592ed 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricReconciler.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricReconciler.java @@ -7,8 +7,11 @@ package com.facebook.react.fabric; -import android.util.Log; +import com.facebook.common.logging.FLog; +import com.facebook.debug.holder.PrinterHolder; +import com.facebook.debug.tags.ReactDebugOverlayTags; import com.facebook.react.common.ArrayUtils; +import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.react.uimanager.ReactShadowNode; import com.facebook.react.uimanager.UIViewOperationQueue; import com.facebook.react.uimanager.ViewAtIndex; @@ -23,7 +26,8 @@ import javax.annotation.Nullable; public class FabricReconciler { private static final String TAG = FabricReconciler.class.getSimpleName(); - private static final boolean DEBUG = true; + private static final boolean DEBUG = ReactBuildConfig.DEBUG || PrinterHolder + .getPrinter().shouldDisplayLogMessage(ReactDebugOverlayTags.FABRIC_RECONCILER); private UIViewOperationQueue uiViewOperationQueue; @@ -104,7 +108,7 @@ public class FabricReconciler { ViewAtIndex[] viewsToAddArray = viewsToAdd.toArray(new ViewAtIndex[viewsToAdd.size()]); int[] tagsToDeleteArray = ArrayUtils.copyListToArray(tagsToDelete); if (DEBUG) { - Log.d( + FLog.d( TAG, "manageChildren.enqueueManageChildren parent: " + parent.getReactTag() + "\n\tIndices2Remove: " + Arrays.toString(indicesToRemoveArray) + @@ -119,7 +123,7 @@ public class FabricReconciler { private void enqueueUpdateProperties(ReactShadowNode node) { int reactTag = node.getReactTag(); if (DEBUG) { - Log.d( + FLog.d( TAG, "manageChildren.enqueueUpdateProperties " + "\n\ttag: " + reactTag + diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 588d7bc59..b0b8edbf7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -12,8 +12,10 @@ import static android.view.View.MeasureSpec.EXACTLY; import static android.view.View.MeasureSpec.UNSPECIFIED; import static com.facebook.react.uimanager.common.UIManagerType.FABRIC; -import android.util.Log; import android.view.View; +import com.facebook.common.logging.FLog; +import com.facebook.debug.holder.PrinterHolder; +import com.facebook.debug.tags.ReactDebugOverlayTags; import com.facebook.infer.annotation.Assertions; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.JavaScriptContextHolder; @@ -26,6 +28,7 @@ import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.common.ReactConstants; import com.facebook.react.common.annotations.VisibleForTesting; +import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.react.fabric.events.FabricEventEmitter; import com.facebook.react.modules.i18nmanager.I18nUtil; import com.facebook.react.uimanager.DisplayMetricsHolder; @@ -56,7 +59,7 @@ import javax.annotation.Nullable; public class FabricUIManager implements UIManager, JSHandler { private static final String TAG = FabricUIManager.class.getSimpleName(); - private static final boolean DEBUG = true; + private static final boolean DEBUG = ReactBuildConfig.DEBUG || PrinterHolder.getPrinter().shouldDisplayLogMessage(ReactDebugOverlayTags.FABRIC_UI_MANAGER); private final RootShadowNodeRegistry mRootShadowNodeRegistry = new RootShadowNodeRegistry(); private final ReactApplicationContext mReactApplicationContext; @@ -100,7 +103,7 @@ public class FabricUIManager implements UIManager, JSHandler { public ReactShadowNode createNode( int reactTag, String viewName, int rootTag, ReadableNativeMap props, long instanceHandle) { if (DEBUG) { - Log.d(TAG, "createNode \n\ttag: " + reactTag + + FLog.d(TAG, "createNode \n\ttag: " + reactTag + "\n\tviewName: " + viewName + "\n\trootTag: " + rootTag + "\n\tprops: " + props); @@ -151,7 +154,7 @@ public class FabricUIManager implements UIManager, JSHandler { @DoNotStrip public ReactShadowNode cloneNode(ReactShadowNode node, long instanceHandle) { if (DEBUG) { - Log.d(TAG, "cloneNode \n\tnode: " + node); + FLog.d(TAG, "cloneNode \n\tnode: " + node); } try { ReactShadowNode clone = node.mutableCopy(instanceHandle); @@ -172,7 +175,7 @@ public class FabricUIManager implements UIManager, JSHandler { @DoNotStrip public ReactShadowNode cloneNodeWithNewChildren(ReactShadowNode node, long instanceHandle) { if (DEBUG) { - Log.d(TAG, "cloneNodeWithNewChildren \n\tnode: " + node); + FLog.d(TAG, "cloneNodeWithNewChildren \n\tnode: " + node); } try { ReactShadowNode clone = node.mutableCopyWithNewChildren(instanceHandle); @@ -194,7 +197,7 @@ public class FabricUIManager implements UIManager, JSHandler { public ReactShadowNode cloneNodeWithNewProps( ReactShadowNode node, @Nullable ReadableNativeMap newProps, long instanceHandle) { if (DEBUG) { - Log.d(TAG, "cloneNodeWithNewProps \n\tnode: " + node + "\n\tprops: " + newProps); + FLog.d(TAG, "cloneNodeWithNewProps \n\tnode: " + node + "\n\tprops: " + newProps); } try { ReactShadowNode clone = node.mutableCopyWithNewProps(instanceHandle, @@ -218,7 +221,7 @@ public class FabricUIManager implements UIManager, JSHandler { public ReactShadowNode cloneNodeWithNewChildrenAndProps( ReactShadowNode node, ReadableNativeMap newProps, long instanceHandle) { if (DEBUG) { - Log.d(TAG, "cloneNodeWithNewChildrenAndProps \n\tnode: " + node + "\n\tnewProps: " + newProps); + FLog.d(TAG, "cloneNodeWithNewChildrenAndProps \n\tnode: " + node + "\n\tnewProps: " + newProps); } try { ReactShadowNode clone = @@ -252,7 +255,7 @@ public class FabricUIManager implements UIManager, JSHandler { @DoNotStrip public void appendChild(ReactShadowNode parent, ReactShadowNode child) { if (DEBUG) { - Log.d(TAG, "appendChild \n\tparent: " + parent + "\n\tchild: " + child); + FLog.d(TAG, "appendChild \n\tparent: " + parent + "\n\tchild: " + child); } try { // If the child to append is shared with another tree (child.getParent() != null), @@ -274,7 +277,7 @@ public class FabricUIManager implements UIManager, JSHandler { @DoNotStrip public List createChildSet(int rootTag) { if (DEBUG) { - Log.d(TAG, "createChildSet rootTag: " + rootTag); + FLog.d(TAG, "createChildSet rootTag: " + rootTag); } return new ArrayList<>(1); } @@ -292,7 +295,7 @@ public class FabricUIManager implements UIManager, JSHandler { try { childList = childList == null ? new LinkedList() : childList; if (DEBUG) { - Log.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList); + FLog.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList); } ReactShadowNode currentRootShadowNode = getRootNode(rootTag); Assertions.assertNotNull( @@ -302,7 +305,7 @@ public class FabricUIManager implements UIManager, JSHandler { currentRootShadowNode = calculateDiffingAndCreateNewRootNode(currentRootShadowNode, childList); if (DEBUG) { - Log.d( + FLog.d( TAG, "ReactShadowNodeHierarchy after diffing: " + currentRootShadowNode.getHierarchyInfo()); } @@ -339,16 +342,17 @@ public class FabricUIManager implements UIManager, JSHandler { } if (DEBUG) { - Log.d( + FLog.d( TAG, "ReactShadowNodeHierarchy before calculateLayout: " + newRootShadowNode.getHierarchyInfo()); } notifyOnBeforeLayoutRecursive(newRootShadowNode); + newRootShadowNode.calculateLayout(); if (DEBUG) { - Log.d( + FLog.d( TAG, "ReactShadowNodeHierarchy after calculateLayout: " + newRootShadowNode.getHierarchyInfo()); } @@ -425,7 +429,7 @@ public class FabricUIManager implements UIManager, JSHandler { public void updateRootLayoutSpecs(int rootViewTag, int widthMeasureSpec, int heightMeasureSpec) { ReactShadowNode rootNode = mRootShadowNodeRegistry.getNode(rootViewTag); if (rootNode == null) { - Log.w(ReactConstants.TAG, "Tried to update non-existent root tag: " + rootViewTag); + FLog.w(ReactConstants.TAG, "Tried to update non-existent root tag: " + rootViewTag); return; } updateRootView(rootNode, widthMeasureSpec, heightMeasureSpec); @@ -439,7 +443,7 @@ public class FabricUIManager implements UIManager, JSHandler { private synchronized void updateRootSize(int rootTag, int newWidth, int newHeight) { ReactShadowNode rootNode = mRootShadowNodeRegistry.getNode(rootTag); if (rootNode == null) { - Log.w( + FLog.w( ReactConstants.TAG, "Tried to update size of non-existent tag: " + rootTag); return; @@ -509,7 +513,7 @@ public class FabricUIManager implements UIManager, JSHandler { // a RuntimeException context.handleException(new RuntimeException(t)); } catch (Exception ex) { - Log.e(TAG, "Exception while executing a Fabric method", t); + FLog.e(TAG, "Exception while executing a Fabric method", t); throw new RuntimeException(ex.getMessage(), t); } } @@ -521,7 +525,7 @@ public class FabricUIManager implements UIManager, JSHandler { long context = mJSContext.get(); long eventTarget = mBinding.createEventTarget(context, instanceHandle); if (DEBUG) { - Log.d( + FLog.d( TAG, "Created EventTarget: " + eventTarget + " for tag: " + reactTag + " with instanceHandle: " + instanceHandle); } @@ -547,7 +551,7 @@ public class FabricUIManager implements UIManager, JSHandler { @DoNotStrip public void invoke(long eventTarget, String name, WritableMap params) { if (DEBUG) { - Log.d( + FLog.d( TAG, "Dispatching event for target: " + eventTarget); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK index 0a449cfd1..99dbb6328 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK @@ -30,6 +30,7 @@ rn_android_library( react_native_target("java/com/facebook/react/animation:animation"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), + react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/module/annotations:annotations"), react_native_target("java/com/facebook/react/modules/core:core"), react_native_target("java/com/facebook/react/modules/i18nmanager:i18nmanager"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java index 3b3929646..c98c12bb0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java @@ -8,8 +8,11 @@ package com.facebook.react.uimanager; import static java.lang.System.arraycopy; -import android.util.Log; +import com.facebook.common.logging.FLog; +import com.facebook.debug.holder.PrinterHolder; +import com.facebook.debug.tags.ReactDebugOverlayTags; import com.facebook.infer.annotation.Assertions; +import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.react.uimanager.annotations.ReactPropertyHolder; import com.facebook.yoga.YogaAlign; import com.facebook.yoga.YogaBaselineFunction; @@ -59,7 +62,7 @@ import javax.annotation.Nullable; @ReactPropertyHolder public class ReactShadowNodeImpl implements ReactShadowNode { - private static final boolean DEBUG = true; + private static final boolean DEBUG = ReactBuildConfig.DEBUG || PrinterHolder.getPrinter().shouldDisplayLogMessage(ReactDebugOverlayTags.FABRIC_UI_MANAGER); private static final String TAG = ReactShadowNodeImpl.class.getSimpleName(); private static final YogaConfig sYogaConfig; static { @@ -75,7 +78,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode Assertions.assertNotNull(oldReactShadowNode); if (DEBUG) { - Log.d( + FLog.d( TAG, "YogaNode started cloning: oldYogaNode: " + oldReactShadowNode + " - parent: " + parentReactShadowNode + " index: " + childIndex);