From d62e4324468a4c2f352eb954fa6bbc85acb2c736 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 14 Jun 2018 18:36:34 -0700 Subject: [PATCH] Adding UIManager performance counters in Fabric Reviewed By: fkgozali Differential Revision: D8381255 fbshipit-source-id: d817557c8a3033d0d7ae47e5ea0a21d224279e29 --- .../react/bridge/PerformanceCounter.java | 4 ++++ .../com/facebook/react/bridge/UIManager.java | 2 +- .../react/fabric/FabricUIManager.java | 24 +++++++++++++++++-- .../react/uimanager/UIManagerModule.java | 7 +++++- 4 files changed, 33 insertions(+), 4 deletions(-) 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 7acd416a9..984eb7859 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,9 @@ package com.facebook.react.bridge; import java.util.Map; public interface PerformanceCounter { + + void profileNextBatch(); + Map getPerformanceCounters(); + } diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java index 875f42cbf..e1f778b8c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java @@ -5,7 +5,7 @@ import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout; import javax.annotation.Nullable; -public interface UIManager extends JSIModule { +public interface UIManager extends JSIModule, PerformanceCounter { /** * Registers a new root view. 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 b0b8edbf7..ea0ff8f2c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -12,6 +12,7 @@ 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.os.SystemClock; import android.view.View; import com.facebook.common.logging.FLog; import com.facebook.debug.holder.PrinterHolder; @@ -19,6 +20,7 @@ import com.facebook.debug.tags.ReactDebugOverlayTags; import com.facebook.infer.annotation.Assertions; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.JavaScriptContextHolder; +import com.facebook.react.bridge.PerformanceCounter; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; @@ -48,6 +50,7 @@ import com.facebook.yoga.YogaDirection; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Map; import javax.annotation.Nullable; /** @@ -73,6 +76,7 @@ public class FabricUIManager implements UIManager, JSHandler { private FabricBinding mBinding; private final FabricEventEmitter mFabricEventEmitter; private long mEventHandlerPointer; + private long mLastCalculateLayoutTime = 0; public FabricUIManager( ReactApplicationContext reactContext, @@ -293,6 +297,7 @@ public class FabricUIManager implements UIManager, JSHandler { @DoNotStrip public synchronized void completeRoot(int rootTag, @Nullable List childList) { try { + long startTime = SystemClock.uptimeMillis(); childList = childList == null ? new LinkedList() : childList; if (DEBUG) { FLog.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList); @@ -312,7 +317,7 @@ public class FabricUIManager implements UIManager, JSHandler { applyUpdatesRecursive(currentRootShadowNode, 0, 0); mUIViewOperationQueue.dispatchViewUpdates( - mCurrentBatch++, System.currentTimeMillis(), System.currentTimeMillis()); + mCurrentBatch++, startTime, mLastCalculateLayoutTime); mRootShadowNodeRegistry.replaceNode(currentRootShadowNode); } catch (Exception e) { @@ -349,7 +354,12 @@ public class FabricUIManager implements UIManager, JSHandler { notifyOnBeforeLayoutRecursive(newRootShadowNode); - newRootShadowNode.calculateLayout(); + long startTime = SystemClock.uptimeMillis(); + try { + newRootShadowNode.calculateLayout(); + } finally{ + mLastCalculateLayoutTime = SystemClock.uptimeMillis() - startTime; + } if (DEBUG) { FLog.d( @@ -572,4 +582,14 @@ public class FabricUIManager implements UIManager, JSHandler { mFabricEventEmitter.close(); } + @Override + public void profileNextBatch() { + mUIViewOperationQueue.profileNextBatch(); + } + + @Override + public Map getPerformanceCounters() { + // TODO change profiling when enabling multi-thread rendering. + return mUIViewOperationQueue.getProfiledBatchPerfCounters(); + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index 9022686a7..f35511c33 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -81,7 +81,7 @@ import javax.annotation.Nullable; */ @ReactModule(name = UIManagerModule.NAME) public class UIManagerModule extends ReactContextBaseJavaModule implements - OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter, UIManager { + OnBatchCompleteListener, LifecycleEventListener, UIManager { /** * Enables lazy discovery of a specific {@link ViewManager} by its name. @@ -286,6 +286,11 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements }; } + @Override + public void profileNextBatch() { + mUIImplementation.profileNextBatch(); + } + @Override public Map getPerformanceCounters() { return mUIImplementation.getProfiledBatchPerfCounters();