Skip to content

Commit

Permalink
Log created views with mounting errors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Andrei Shikov authored and facebook-github-bot committed Sep 1, 2021
1 parent 963254e commit 8b4f507
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -274,10 +275,17 @@ private boolean dispatchMountItems() {
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);
Expand Down
Expand Up @@ -963,6 +963,25 @@ public View getView(int reactTag) {
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.
Expand Down

0 comments on commit 8b4f507

Please sign in to comment.