Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 531730ee authored by Nick Chameyev's avatar Nick Chameyev
Browse files

Add traces for remote display change

Adding perfetto traces to remote display change
logic to understand the timings of this
flow in case of problems.

Bug: 289783110
Flag: none
Test: captured unfold perfetto trace
Change-Id: Ie5d16b1e26bcb8965f9b16380ed3b135d27e6b60
parent 5c8908c9
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.common;

import android.annotation.Nullable;
import android.os.RemoteException;
import android.os.Trace;
import android.util.Slog;
import android.view.IDisplayChangeWindowCallback;
import android.view.IDisplayChangeWindowController;
@@ -40,6 +41,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
 */
public class DisplayChangeController {
    private static final String TAG = DisplayChangeController.class.getSimpleName();
    private static final String HANDLE_DISPLAY_CHANGE_TRACE_TAG = "HandleRemoteDisplayChange";

    private final ShellExecutor mMainExecutor;
    private final IWindowManager mWmService;
@@ -81,9 +83,15 @@ public class DisplayChangeController {
    /** Query all listeners for changes that should happen on display change. */
    void dispatchOnDisplayChange(WindowContainerTransaction outWct, int displayId,
            int fromRotation, int toRotation, DisplayAreaInfo newDisplayAreaInfo) {
        if (Trace.isTagEnabled(Trace.TRACE_TAG_WINDOW_MANAGER)) {
            Trace.beginSection("dispatchOnDisplayChange");
        }
        for (OnDisplayChangingListener c : mDisplayChangeListener) {
            c.onDisplayChange(displayId, fromRotation, toRotation, newDisplayAreaInfo, outWct);
        }
        if (Trace.isTagEnabled(Trace.TRACE_TAG_WINDOW_MANAGER)) {
            Trace.endSection();
        }
    }

    private void onDisplayChange(int displayId, int fromRotation, int toRotation,
@@ -94,6 +102,10 @@ public class DisplayChangeController {
            callback.continueDisplayChange(t);
        } catch (RemoteException e) {
            Slog.e(TAG, "Failed to continue handling display change", e);
        } finally {
            if (Trace.isTagEnabled(Trace.TRACE_TAG_WINDOW_MANAGER)) {
                Trace.endAsyncSection(HANDLE_DISPLAY_CHANGE_TRACE_TAG, callback.hashCode());
            }
        }
    }

@@ -103,6 +115,9 @@ public class DisplayChangeController {
        @Override
        public void onDisplayChange(int displayId, int fromRotation, int toRotation,
                DisplayAreaInfo newDisplayAreaInfo, IDisplayChangeWindowCallback callback) {
            if (Trace.isTagEnabled(Trace.TRACE_TAG_WINDOW_MANAGER)) {
                Trace.beginAsyncSection(HANDLE_DISPLAY_CHANGE_TRACE_TAG, callback.hashCode());
            }
            mMainExecutor.execute(() -> DisplayChangeController.this
                    .onDisplayChange(displayId, fromRotation, toRotation,
                            newDisplayAreaInfo, callback));
+21 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_CONFIGURATION
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.RemoteException;
import android.os.Trace;
import android.util.Slog;
import android.view.IDisplayChangeWindowCallback;
import android.window.DisplayAreaInfo;
@@ -40,6 +41,7 @@ import java.util.List;
public class RemoteDisplayChangeController {

    private static final String TAG = "RemoteDisplayChangeController";
    private static final String REMOTE_DISPLAY_CHANGE_TRACE_TAG = "RemoteDisplayChange";

    private static final int REMOTE_DISPLAY_CHANGE_TIMEOUT_MS = 800;

@@ -82,6 +84,10 @@ public class RemoteDisplayChangeController {
        }
        mCallbacks.add(callback);

        if (Trace.isTagEnabled(Trace.TRACE_TAG_WINDOW_MANAGER)) {
            Trace.beginAsyncSection(REMOTE_DISPLAY_CHANGE_TRACE_TAG, callback.hashCode());
        }

        if (newDisplayAreaInfo != null) {
            ProtoLog.v(WM_DEBUG_CONFIGURATION,
                    "Starting remote display change: "
@@ -122,6 +128,10 @@ public class RemoteDisplayChangeController {
                    mCallbacks.clear();
                }
                callback.onContinueRemoteDisplayChange(null /* transaction */);

                if (Trace.isTagEnabled(Trace.TRACE_TAG_WINDOW_MANAGER)) {
                    Trace.endAsyncSection(REMOTE_DISPLAY_CHANGE_TRACE_TAG, callback.hashCode());
                }
            }
        }
    }
@@ -137,13 +147,23 @@ public class RemoteDisplayChangeController {
            for (int i = 0; i < idx; ++i) {
                // Expect remote callbacks in order. If they don't come in order, then force
                // ordering by continuing everything up until this one with empty transactions.
                mCallbacks.get(i).onContinueRemoteDisplayChange(null /* transaction */);
                ContinueRemoteDisplayChangeCallback currentCallback = mCallbacks.get(i);
                currentCallback.onContinueRemoteDisplayChange(null /* transaction */);

                if (Trace.isTagEnabled(Trace.TRACE_TAG_WINDOW_MANAGER)) {
                    Trace.endAsyncSection(REMOTE_DISPLAY_CHANGE_TRACE_TAG,
                            currentCallback.hashCode());
                }
            }
            mCallbacks.subList(0, idx + 1).clear();
            if (mCallbacks.isEmpty()) {
                mService.mH.removeCallbacks(mTimeoutRunnable);
            }
            callback.onContinueRemoteDisplayChange(transaction);

            if (Trace.isTagEnabled(Trace.TRACE_TAG_WINDOW_MANAGER)) {
                Trace.endAsyncSection(REMOTE_DISPLAY_CHANGE_TRACE_TAG, callback.hashCode());
            }
        }
    }