From c48601b0af1f16afc20e50dfdc6b9348823e8881 Mon Sep 17 00:00:00 2001 From: Jernej Virag Date: Fri, 29 Apr 2022 15:21:57 +0000 Subject: [PATCH] Trace Window relayout reasons Window relayouts (and subsequent binder calls) are common performance issues and the reason for relayout can be hard to determine in Perfetto traces. This adds reason for triggered window relayout to the trace if View tracing is currently enabled. Bug: 231121537 Test: Using perfetto, see https://screenshot.googleplex.com/AgsM2pfidDAav7j Change-Id: Ib1d9b673517eb80b09c6bacedd34e26cb502877b --- core/java/android/view/ViewRootImpl.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index b7a2aa0b01748..c57d177a02e00 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -2895,6 +2895,14 @@ public final class ViewRootImpl implements ViewParent, if (mFirst || windowShouldResize || viewVisibilityChanged || params != null || mForceNextWindowRelayout) { + if (Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) { + Trace.traceBegin(Trace.TRACE_TAG_VIEW, + TextUtils.formatSimple("relayoutWindow#" + + "first=%b/resize=%b/vis=%b/params=%b/force=%b", + mFirst, windowShouldResize, viewVisibilityChanged, params != null, + mForceNextWindowRelayout)); + } + mForceNextWindowRelayout = false; // If this window is giving internal insets to the window manager, then we want to first @@ -3085,6 +3093,10 @@ public final class ViewRootImpl implements ViewParent, } } } catch (RemoteException e) { + } finally { + if (Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) { + Trace.traceEnd(Trace.TRACE_TAG_VIEW); + } } if (DEBUG_ORIENTATION) Log.v(