Log created views with mounting errors

Summary:
Displays views from the surface mounting manager after we hit a crash during mounting.
This change should help with debugging mounting crashes (e.g. when view is added before removal)

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D30681339

fbshipit-source-id: f83cecaf8e418a2fa5aa0713513c51bb1be77013
This commit is contained in:
Andrei Shikov
2021-09-01 07:31:18 -07:00
committed by Facebook GitHub Bot
parent 963254e2ec
commit 8b4f5073a1
2 changed files with 28 additions and 1 deletions
@@ -13,6 +13,7 @@ import static com.facebook.react.fabric.FabricUIManager.ENABLE_FABRIC_LOGS;
import static com.facebook.react.fabric.FabricUIManager.IS_DEVELOPMENT_ENVIRONMENT;
import android.os.SystemClock;
import android.view.View;
import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -274,10 +275,17 @@ public class MountItemDispatcher {
executeOrEnqueue(mountItem);
} catch (Throwable e) {
// If there's an exception, we want to log diagnostics in prod and rethrow.
FLog.e(TAG, "dispatchMountItems: caught exception, displaying all MountItems", e);
FLog.e(TAG, "dispatchMountItems: caught exception, displaying mount state", e);
for (MountItem m : mountItemsToDispatch) {
printMountItem(m, "dispatchMountItems: mountItem");
}
if (mountItem.getSurfaceId() != View.NO_ID) {
SurfaceMountingManager surfaceManager =
mMountingManager.getSurfaceManager(mountItem.getSurfaceId());
if (surfaceManager != null) {
surfaceManager.printSurfaceState();
}
}
if (ReactIgnorableMountingException.isIgnorable(e)) {
ReactSoftExceptionLogger.logSoftException(TAG, e);
@@ -963,6 +963,25 @@ public class SurfaceMountingManager {
return (ViewGroupManager<ViewGroup>) viewState.mViewManager;
}
public void printSurfaceState() {
FLog.e(TAG, "Views created for surface {%d}:", getSurfaceId());
for (ViewState viewState : mTagToViewState.values()) {
String viewManagerName =
viewState.mViewManager != null ? viewState.mViewManager.getName() : null;
@Nullable View view = viewState.mView;
@Nullable View parent = view != null ? (View) view.getParent() : null;
@Nullable Integer parentTag = parent != null ? parent.getId() : null;
FLog.e(
TAG,
"<%s id=%d parentTag=%s isRoot=%b />",
viewManagerName,
viewState.mReactTag,
parentTag,
viewState.mIsRoot);
}
}
/**
* This class holds view state for react tags. Objects of this class are stored into the {@link
* #mTagToViewState}, and they should be updated in the same thread.