Add systrace logging for Fabric android

Reviewed By: fkgozali

Differential Revision: D8387339

fbshipit-source-id: 2e202566541cc25fb6b8773a94e607e8b40fb0ce
This commit is contained in:
David Vacca
2018-06-14 18:36:36 -07:00
committed by Facebook Github Bot
parent d62e432446
commit 0dc86dfd91
4 changed files with 151 additions and 54 deletions

View File

@@ -15,6 +15,7 @@ rn_android_library(
],
deps = [
YOGA_TARGET,
react_native_dep("java/com/facebook/systrace:systrace"),
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"),

View File

@@ -15,6 +15,8 @@ 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;
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
@@ -26,7 +28,7 @@ import javax.annotation.Nullable;
public class FabricReconciler {
private static final String TAG = FabricReconciler.class.getSimpleName();
private static final boolean DEBUG = ReactBuildConfig.DEBUG || PrinterHolder
private static final boolean DEBUG = ReactBuildConfig.DEBUG || PrinterHolder
.getPrinter().shouldDisplayLogMessage(ReactDebugOverlayTags.FABRIC_RECONCILER);
private UIViewOperationQueue uiViewOperationQueue;
@@ -36,9 +38,18 @@ public class FabricReconciler {
}
public void manageChildren(ReactShadowNode previousRootShadowNode, ReactShadowNode newRootShadowNode) {
List<ReactShadowNode> prevList =
previousRootShadowNode == null ? null : previousRootShadowNode.getChildrenList();
manageChildren(newRootShadowNode, prevList, newRootShadowNode.getChildrenList());
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricReconciler.manageChildren")
.flush();
try {
List<ReactShadowNode> prevList =
previousRootShadowNode == null ? null : previousRootShadowNode.getChildrenList();
manageChildren(newRootShadowNode, prevList, newRootShadowNode.getChildrenList());
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
private void manageChildren(

View File

@@ -46,6 +46,8 @@ import com.facebook.react.uimanager.ViewManagerRegistry;
import com.facebook.react.uimanager.common.MeasureSpecProvider;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
import com.facebook.yoga.YogaDirection;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -160,6 +162,10 @@ public class FabricUIManager implements UIManager, JSHandler {
if (DEBUG) {
FLog.d(TAG, "cloneNode \n\tnode: " + node);
}
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricUIManager.cloneNode")
.flush();
try {
ReactShadowNode clone = node.mutableCopy(instanceHandle);
assertReactShadowNodeCopy(node, clone);
@@ -167,6 +173,8 @@ public class FabricUIManager implements UIManager, JSHandler {
} catch (Throwable t) {
handleException(node, t);
return null;
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
@@ -181,6 +189,10 @@ public class FabricUIManager implements UIManager, JSHandler {
if (DEBUG) {
FLog.d(TAG, "cloneNodeWithNewChildren \n\tnode: " + node);
}
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricUIManager.cloneNodeWithNewChildren")
.flush();
try {
ReactShadowNode clone = node.mutableCopyWithNewChildren(instanceHandle);
assertReactShadowNodeCopy(node, clone);
@@ -188,6 +200,8 @@ public class FabricUIManager implements UIManager, JSHandler {
} catch (Throwable t) {
handleException(node, t);
return null;
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
@@ -203,6 +217,10 @@ public class FabricUIManager implements UIManager, JSHandler {
if (DEBUG) {
FLog.d(TAG, "cloneNodeWithNewProps \n\tnode: " + node + "\n\tprops: " + newProps);
}
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricUIManager.cloneNodeWithNewProps")
.flush();
try {
ReactShadowNode clone = node.mutableCopyWithNewProps(instanceHandle,
newProps == null ? null : new ReactStylesDiffMap(newProps));
@@ -211,6 +229,8 @@ public class FabricUIManager implements UIManager, JSHandler {
} catch (Throwable t) {
handleException(node, t);
return null;
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
@@ -227,6 +247,10 @@ public class FabricUIManager implements UIManager, JSHandler {
if (DEBUG) {
FLog.d(TAG, "cloneNodeWithNewChildrenAndProps \n\tnode: " + node + "\n\tnewProps: " + newProps);
}
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricUIManager.cloneNodeWithNewChildrenAndProps")
.flush();
try {
ReactShadowNode clone =
node.mutableCopyWithNewChildrenAndProps(instanceHandle,
@@ -236,6 +260,8 @@ public class FabricUIManager implements UIManager, JSHandler {
} catch (Throwable t) {
handleException(node, t);
return null;
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
@@ -261,6 +287,10 @@ public class FabricUIManager implements UIManager, JSHandler {
if (DEBUG) {
FLog.d(TAG, "appendChild \n\tparent: " + parent + "\n\tchild: " + child);
}
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricUIManager.appendChild")
.flush();
try {
// If the child to append is shared with another tree (child.getParent() != null),
// then we add a mutation of it. In the future this will be performed by FabricJS / Fiber.
@@ -271,6 +301,8 @@ public class FabricUIManager implements UIManager, JSHandler {
parent.addChildAt(child, parent.getChildCount());
} catch (Throwable t) {
handleException(parent, t);
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
@@ -296,6 +328,10 @@ public class FabricUIManager implements UIManager, JSHandler {
@DoNotStrip
public synchronized void completeRoot(int rootTag, @Nullable List<ReactShadowNode> childList) {
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricUIManager.completeRoot")
.flush();
try {
long startTime = SystemClock.uptimeMillis();
childList = childList == null ? new LinkedList<ReactShadowNode>() : childList;
@@ -315,13 +351,15 @@ public class FabricUIManager implements UIManager, JSHandler {
"ReactShadowNodeHierarchy after diffing: " + currentRootShadowNode.getHierarchyInfo());
}
applyUpdatesRecursive(currentRootShadowNode, 0, 0);
applyUpdatesRecursive(currentRootShadowNode);
mUIViewOperationQueue.dispatchViewUpdates(
mCurrentBatch++, startTime, mLastCalculateLayoutTime);
mRootShadowNodeRegistry.replaceNode(currentRootShadowNode);
} catch (Exception e) {
handleException(getRootNode(rootTag), e);
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
@@ -340,35 +378,63 @@ public class FabricUIManager implements UIManager, JSHandler {
}
private ReactShadowNode calculateDiffingAndCreateNewRootNode(
ReactShadowNode currentRootShadowNode, List<ReactShadowNode> newChildList) {
ReactShadowNode newRootShadowNode = currentRootShadowNode.mutableCopyWithNewChildren(currentRootShadowNode.getInstanceHandle());
for (ReactShadowNode child : newChildList) {
appendChild(newRootShadowNode, child);
ReactShadowNode currentRootShadowNode, List<ReactShadowNode> newChildList) {
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricUIManager.calculateDiffingAndCreateNewRootNode")
.flush();
try {
ReactShadowNode newRootShadowNode = currentRootShadowNode.mutableCopyWithNewChildren(currentRootShadowNode.getInstanceHandle());
for (ReactShadowNode child : newChildList) {
appendChild(newRootShadowNode, child);
}
if (DEBUG) {
FLog.d(
TAG,
"ReactShadowNodeHierarchy before calculateLayout: " + newRootShadowNode.getHierarchyInfo());
}
notifyOnBeforeLayoutRecursive(newRootShadowNode);
calculateLayout(newRootShadowNode);
if (DEBUG) {
FLog.d(
TAG,
"ReactShadowNodeHierarchy after calculateLayout: " + newRootShadowNode.getHierarchyInfo());
}
mFabricReconciler.manageChildren(currentRootShadowNode, newRootShadowNode);
return newRootShadowNode;
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
if (DEBUG) {
FLog.d(
TAG,
"ReactShadowNodeHierarchy before calculateLayout: " + newRootShadowNode.getHierarchyInfo());
}
notifyOnBeforeLayoutRecursive(newRootShadowNode);
private void calculateLayout(ReactShadowNode newRootShadowNode) {
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricUIManager.calculateLayout")
.flush();
long startTime = SystemClock.uptimeMillis();
try {
newRootShadowNode.calculateLayout();
} finally{
mLastCalculateLayoutTime = SystemClock.uptimeMillis() - startTime;
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
if (DEBUG) {
FLog.d(
TAG,
"ReactShadowNodeHierarchy after calculateLayout: " + newRootShadowNode.getHierarchyInfo());
private void applyUpdatesRecursive(ReactShadowNode node) {
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManager.applyUpdatesRecursive")
.flush();
try {
applyUpdatesRecursive(node, 0, 0);
} finally{
SystraceMessage.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
mFabricReconciler.manageChildren(currentRootShadowNode, newRootShadowNode);
return newRootShadowNode;
}
private void applyUpdatesRecursive(ReactShadowNode node, float absoluteX, float absoluteY) {
@@ -411,27 +477,36 @@ public class FabricUIManager implements UIManager, JSHandler {
@DoNotStrip
public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(
final T rootView) {
final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
ThemedReactContext themedRootContext =
new ThemedReactContext(mReactApplicationContext, rootView.getContext());
ReactShadowNode rootShadowNode = createRootShadowNode(rootTag, themedRootContext);
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricUIManager.addRootView")
.flush();
try {
final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
ThemedReactContext themedRootContext =
new ThemedReactContext(mReactApplicationContext, rootView.getContext());
int widthMeasureSpec = rootView.getWidthMeasureSpec();
int heightMeasureSpec = rootView.getHeightMeasureSpec();
updateRootView(rootShadowNode, widthMeasureSpec, heightMeasureSpec);
ReactShadowNode rootShadowNode = createRootShadowNode(rootTag, themedRootContext);
rootView.setOnSizeChangedListener(
new SizeMonitoringFrameLayout.OnSizeChangedListener() {
@Override
public void onSizeChanged(final int width, final int height, int oldW, int oldH) {
updateRootSize(rootTag, width, height);
}
});
int widthMeasureSpec = rootView.getWidthMeasureSpec();
int heightMeasureSpec = rootView.getHeightMeasureSpec();
updateRootView(rootShadowNode, widthMeasureSpec, heightMeasureSpec);
mRootShadowNodeRegistry.registerNode(rootShadowNode);
mUIViewOperationQueue.addRootView(rootTag, rootView, themedRootContext);
return rootTag;
rootView.setOnSizeChangedListener(
new SizeMonitoringFrameLayout.OnSizeChangedListener() {
@Override
public void onSizeChanged(final int width, final int height, int oldW, int oldH) {
updateRootSize(rootTag, width, height);
}
});
mRootShadowNodeRegistry.registerNode(rootShadowNode);
mUIViewOperationQueue.addRootView(rootTag, rootView, themedRootContext);
return rootTag;
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
@Override

View File

@@ -14,6 +14,8 @@ 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.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
import com.facebook.yoga.YogaAlign;
import com.facebook.yoga.YogaBaselineFunction;
import com.facebook.yoga.YogaConfig;
@@ -72,21 +74,29 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
public YogaNode cloneNode(YogaNode oldYogaNode,
YogaNode parent,
int childIndex) {
ReactShadowNodeImpl parentReactShadowNode = (ReactShadowNodeImpl) parent.getData();
Assertions.assertNotNull(parentReactShadowNode);
ReactShadowNodeImpl oldReactShadowNode = (ReactShadowNodeImpl) oldYogaNode.getData();
Assertions.assertNotNull(oldReactShadowNode);
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricReconciler.YogaNodeCloneFunction")
.flush();
try {
ReactShadowNodeImpl parentReactShadowNode = (ReactShadowNodeImpl) parent.getData();
Assertions.assertNotNull(parentReactShadowNode);
ReactShadowNodeImpl oldReactShadowNode = (ReactShadowNodeImpl) oldYogaNode.getData();
Assertions.assertNotNull(oldReactShadowNode);
if (DEBUG) {
FLog.d(
TAG,
"YogaNode started cloning: oldYogaNode: " + oldReactShadowNode + " - parent: "
+ parentReactShadowNode + " index: " + childIndex);
if (DEBUG) {
FLog.d(
TAG,
"YogaNode started cloning: oldYogaNode: " + oldReactShadowNode + " - parent: "
+ parentReactShadowNode + " index: " + childIndex);
}
ReactShadowNodeImpl newNode = oldReactShadowNode.mutableCopy(oldReactShadowNode.getInstanceHandle());
parentReactShadowNode.replaceChild(newNode, childIndex);
return newNode.mYogaNode;
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
ReactShadowNodeImpl newNode = oldReactShadowNode.mutableCopy(oldReactShadowNode.getInstanceHandle());
parentReactShadowNode.replaceChild(newNode, childIndex);
return newNode.mYogaNode;
}
});
}