Add perf tracing for several key operations in TaskView lifecycle.

Fix: 402622741
Test: Manually looking at perf traces
Flag: EXEMPT - tracing only
Change-Id: If42a30d83dd72ebfe4074fedd7bdefcd102881d6
This commit is contained in:
Uwais Ashraf
2025-03-12 05:52:37 +00:00
parent b615b9bdaf
commit d4b187b997
4 changed files with 256 additions and 203 deletions
@@ -17,6 +17,8 @@
package com.android.quickstep.views;
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.os.Trace.traceBegin;
import static android.os.Trace.traceEnd;
import static android.view.Surface.ROTATION_0;
import static android.view.View.MeasureSpec.EXACTLY;
import static android.view.View.MeasureSpec.makeMeasureSpec;
@@ -104,6 +106,7 @@ import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.Trace;
import android.os.UserHandle;
import android.os.VibrationEffect;
import android.text.Layout;
@@ -139,6 +142,7 @@ import androidx.annotation.UiThread;
import androidx.core.graphics.ColorUtils;
import androidx.dynamicanimation.animation.SpringAnimation;
import com.android.app.tracing.TraceUtilsKt;
import com.android.internal.jank.Cuj;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseActivity.MultiWindowModeChangedListener;
@@ -1292,6 +1296,7 @@ public abstract class RecentsView<
@Override
public void onViewRemoved(View child) {
traceBegin(Trace.TRACE_TAG_APP, "RecentsView.onViewRemoved");
super.onViewRemoved(child);
// Clear the task data for the removed child if it was visible unless:
// - It's the initial taskview for entering split screen, we only pretend to dismiss the
@@ -1303,6 +1308,7 @@ public abstract class RecentsView<
clearAndRecycleTaskView((TaskView) child);
}
}
traceEnd(Trace.TRACE_TAG_APP);
}
private void clearAndRecycleTaskView(TaskView taskView) {
@@ -1321,6 +1327,7 @@ public abstract class RecentsView<
@Override
public void onViewAdded(View child) {
traceBegin(Trace.TRACE_TAG_APP, "RecentsView.onViewAdded");
super.onViewAdded(child);
if (child instanceof TaskView) {
mTaskViewCount++;
@@ -1331,6 +1338,7 @@ public abstract class RecentsView<
child.setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_LTR : View.LAYOUT_DIRECTION_RTL);
mActionsView.updateHiddenFlags(HIDDEN_NO_TASKS, false);
updateEmptyMessage();
traceEnd(Trace.TRACE_TAG_APP);
}
@Override
@@ -1927,6 +1935,9 @@ public abstract class RecentsView<
return;
}
// Start here to avoid early returns and empty cases which have special logic
traceBegin(Trace.TRACE_TAG_APP, "RecentsView.applyLoadPlan");
TaskView currentTaskView = getTaskViewAt(mCurrentPage);
int[] currentTaskIds = null;
// Track the current DesktopTaskView through [deskId] as a desk can be empty without any
@@ -1972,8 +1983,9 @@ public abstract class RecentsView<
// TaskIds will no longer be valid after remove and re-add, clearing mTopRowIdSet.
mAnyTaskHasBeenDismissed = false;
mTopRowIdSet.clear();
traceBegin(Trace.TRACE_TAG_APP, "RecentsView.applyLoadPlan.removeAllViews");
removeAllViews();
traceEnd(Trace.TRACE_TAG_APP);
// If we are entering Overview as a result of initiating a split from somewhere else
// (e.g. split from Home), we need to make sure the staged app is not drawn as a thumbnail.
int stagedTaskIdToBeRemoved;
@@ -2000,6 +2012,7 @@ public abstract class RecentsView<
// Add `mAddDesktopButton` as the first child.
addView(mAddDesktopButton);
}
traceBegin(Trace.TRACE_TAG_APP, "RecentsView.applyLoadPlan.forLoop");
// Add views as children based on whether it's grouped or single task. Looping through
// taskGroups backwards populates the thumbnail grid from least recent to most recent.
@@ -2019,8 +2032,11 @@ public abstract class RecentsView<
// If we need to remove half of a pair of tasks, force a TaskView with Type.SINGLE
// to be a temporary container for the remaining task.
traceBegin(Trace.TRACE_TAG_APP, "RecentsView.applyLoadPlan.forLoop.createTaskView");
TaskView taskView = getTaskViewFromPool(
containsStagedTask ? TaskViewType.SINGLE : groupTask.taskViewType);
traceEnd(Trace.TRACE_TAG_APP);
traceBegin(Trace.TRACE_TAG_APP, "RecentsView.applyLoadPlan.forLoop.bind");
if (taskView instanceof GroupedTaskView groupedTaskView) {
var splitTask = (SplitTask) groupTask;
groupedTaskView.bind(splitTask.getTopLeftTask(),
@@ -2038,13 +2054,18 @@ public abstract class RecentsView<
taskView.bind(((SingleTask) groupTask).getTask(), mOrientationState,
mTaskOverlayFactory);
}
traceEnd(Trace.TRACE_TAG_APP);
traceBegin(Trace.TRACE_TAG_APP, "RecentsView.applyLoadPlan.forLoop.addTaskView");
addView(taskView);
traceEnd(Trace.TRACE_TAG_APP);
// enables instance filtering if the feature flag for it is on
if (FeatureFlags.ENABLE_MULTI_INSTANCE.get()) {
taskView.setUpShowAllInstancesListener();
}
}
// For loop end trace
traceEnd(Trace.TRACE_TAG_APP);
addView(mClearAllButton);
@@ -2064,8 +2085,10 @@ public abstract class RecentsView<
setFocusedTaskViewId(
newFocusedTaskView != null ? newFocusedTaskView.getTaskViewId() : INVALID_TASK_ID);
traceBegin(Trace.TRACE_TAG_APP, "RecentsView.applyLoadPlan.layouts");
updateTaskSize();
updateChildTaskOrientations();
traceEnd(Trace.TRACE_TAG_APP);
TaskView newRunningTaskView = mUtils.getDesktopTaskViewForDeskId(runningTaskViewDeskId);
if (newRunningTaskView == null) {
@@ -2120,6 +2143,7 @@ public abstract class RecentsView<
});
}
traceBegin(Trace.TRACE_TAG_APP, "RecentsView.applyLoadPlan.cleanupStates");
if (mIgnoreResetTaskId != INVALID_TASK_ID &&
getTaskViewByTaskId(mIgnoreResetTaskId) != ignoreResetTaskView) {
// If the taskView mapping is changing, do not preserve the visuals. Since we are
@@ -2134,6 +2158,10 @@ public abstract class RecentsView<
if (isPageScrollsInitialized()) {
onPageScrollsInitialized();
}
traceEnd(Trace.TRACE_TAG_APP);
// applyLoadPlan end trace
traceEnd(Trace.TRACE_TAG_APP);
}
private boolean isModal() {