Adding UIManager performance counters in Fabric
Reviewed By: fkgozali Differential Revision: D8381255 fbshipit-source-id: d817557c8a3033d0d7ae47e5ea0a21d224279e29
This commit is contained in:
parent
e773b36990
commit
d62e432446
|
@ -9,5 +9,9 @@ package com.facebook.react.bridge;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface PerformanceCounter {
|
public interface PerformanceCounter {
|
||||||
|
|
||||||
|
void profileNextBatch();
|
||||||
|
|
||||||
Map<String, Long> getPerformanceCounters();
|
Map<String, Long> getPerformanceCounters();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public interface UIManager extends JSIModule {
|
public interface UIManager extends JSIModule, PerformanceCounter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a new root view.
|
* Registers a new root view.
|
||||||
|
|
|
@ -12,6 +12,7 @@ import static android.view.View.MeasureSpec.EXACTLY;
|
||||||
import static android.view.View.MeasureSpec.UNSPECIFIED;
|
import static android.view.View.MeasureSpec.UNSPECIFIED;
|
||||||
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
|
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
|
||||||
|
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import com.facebook.common.logging.FLog;
|
import com.facebook.common.logging.FLog;
|
||||||
import com.facebook.debug.holder.PrinterHolder;
|
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.infer.annotation.Assertions;
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
import com.facebook.react.bridge.JavaScriptContextHolder;
|
import com.facebook.react.bridge.JavaScriptContextHolder;
|
||||||
|
import com.facebook.react.bridge.PerformanceCounter;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReadableArray;
|
import com.facebook.react.bridge.ReadableArray;
|
||||||
import com.facebook.react.bridge.ReadableMap;
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
|
@ -48,6 +50,7 @@ import com.facebook.yoga.YogaDirection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,6 +76,7 @@ public class FabricUIManager implements UIManager, JSHandler {
|
||||||
private FabricBinding mBinding;
|
private FabricBinding mBinding;
|
||||||
private final FabricEventEmitter mFabricEventEmitter;
|
private final FabricEventEmitter mFabricEventEmitter;
|
||||||
private long mEventHandlerPointer;
|
private long mEventHandlerPointer;
|
||||||
|
private long mLastCalculateLayoutTime = 0;
|
||||||
|
|
||||||
public FabricUIManager(
|
public FabricUIManager(
|
||||||
ReactApplicationContext reactContext,
|
ReactApplicationContext reactContext,
|
||||||
|
@ -293,6 +297,7 @@ public class FabricUIManager implements UIManager, JSHandler {
|
||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
public synchronized void completeRoot(int rootTag, @Nullable List<ReactShadowNode> childList) {
|
public synchronized void completeRoot(int rootTag, @Nullable List<ReactShadowNode> childList) {
|
||||||
try {
|
try {
|
||||||
|
long startTime = SystemClock.uptimeMillis();
|
||||||
childList = childList == null ? new LinkedList<ReactShadowNode>() : childList;
|
childList = childList == null ? new LinkedList<ReactShadowNode>() : childList;
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
FLog.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList);
|
FLog.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList);
|
||||||
|
@ -312,7 +317,7 @@ public class FabricUIManager implements UIManager, JSHandler {
|
||||||
|
|
||||||
applyUpdatesRecursive(currentRootShadowNode, 0, 0);
|
applyUpdatesRecursive(currentRootShadowNode, 0, 0);
|
||||||
mUIViewOperationQueue.dispatchViewUpdates(
|
mUIViewOperationQueue.dispatchViewUpdates(
|
||||||
mCurrentBatch++, System.currentTimeMillis(), System.currentTimeMillis());
|
mCurrentBatch++, startTime, mLastCalculateLayoutTime);
|
||||||
|
|
||||||
mRootShadowNodeRegistry.replaceNode(currentRootShadowNode);
|
mRootShadowNodeRegistry.replaceNode(currentRootShadowNode);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -349,7 +354,12 @@ public class FabricUIManager implements UIManager, JSHandler {
|
||||||
|
|
||||||
notifyOnBeforeLayoutRecursive(newRootShadowNode);
|
notifyOnBeforeLayoutRecursive(newRootShadowNode);
|
||||||
|
|
||||||
newRootShadowNode.calculateLayout();
|
long startTime = SystemClock.uptimeMillis();
|
||||||
|
try {
|
||||||
|
newRootShadowNode.calculateLayout();
|
||||||
|
} finally{
|
||||||
|
mLastCalculateLayoutTime = SystemClock.uptimeMillis() - startTime;
|
||||||
|
}
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
FLog.d(
|
FLog.d(
|
||||||
|
@ -572,4 +582,14 @@ public class FabricUIManager implements UIManager, JSHandler {
|
||||||
mFabricEventEmitter.close();
|
mFabricEventEmitter.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void profileNextBatch() {
|
||||||
|
mUIViewOperationQueue.profileNextBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Long> getPerformanceCounters() {
|
||||||
|
// TODO change profiling when enabling multi-thread rendering.
|
||||||
|
return mUIViewOperationQueue.getProfiledBatchPerfCounters();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ import javax.annotation.Nullable;
|
||||||
*/
|
*/
|
||||||
@ReactModule(name = UIManagerModule.NAME)
|
@ReactModule(name = UIManagerModule.NAME)
|
||||||
public class UIManagerModule extends ReactContextBaseJavaModule implements
|
public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||||
OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter, UIManager {
|
OnBatchCompleteListener, LifecycleEventListener, UIManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables lazy discovery of a specific {@link ViewManager} by its name.
|
* 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
|
@Override
|
||||||
public Map<String, Long> getPerformanceCounters() {
|
public Map<String, Long> getPerformanceCounters() {
|
||||||
return mUIImplementation.getProfiledBatchPerfCounters();
|
return mUIImplementation.getProfiledBatchPerfCounters();
|
||||||
|
|
Loading…
Reference in New Issue