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

Commit 2e3d3042 authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Add perfetto traces to LauncherInstrumentation

This will help understanding what's taking time in those tests, and optimize the runtime to add more perfromance tests to presubmits.

Bug: 332823157
Test: perfetto trace
Flag: NONE adding traces
Change-Id: I806c2cd103ff58a4467e48b3da5e95f7f51743f3
parent b41def03
Loading
Loading
Loading
Loading
+40 −20
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import android.os.DeadObjectException;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.Trace;
import android.text.TextUtils;
import android.util.Log;
import android.view.InputDevice;
@@ -524,16 +525,19 @@ public final class LauncherInstrumentation {

    Closable addContextLayer(String piece) {
        mDiagnosticContext.addLast(piece);
        Trace.beginSection("Context: " + piece);
        log("Entering context: " + piece);
        return () -> {
            Trace.endSection();
            log("Leaving context: " + piece);
            mDiagnosticContext.removeLast();
        };
    }

    public void dumpViewHierarchy() {
        final ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try {
            Trace.beginSection("dumpViewHierarchy");
            final ByteArrayOutputStream stream = new ByteArrayOutputStream();
            mDevice.dumpWindowHierarchy(stream);
            stream.flush();
            stream.close();
@@ -542,6 +546,8 @@ public final class LauncherInstrumentation {
            }
        } catch (IOException e) {
            Log.e(TAG, "error dumping XML to logcat", e);
        } finally {
            Trace.endSection();
        }
    }

@@ -621,6 +627,8 @@ public final class LauncherInstrumentation {
     */
    public void checkForAnomaly(
            boolean ignoreNavmodeChangeStates, boolean ignoreOnlySystemUiViews) {
        try {
            Trace.beginSection("checkForAnomaly");
            if (mTestAnomalyChecker != null) mTestAnomalyChecker.run();

            final String systemAnomalyMessage =
@@ -631,6 +639,9 @@ public final class LauncherInstrumentation {
                        "http://go/tapl : Tests are broken by a non-Launcher system error: "
                                + systemAnomalyMessage, false)));
            }
        } finally {
            Trace.endSection();
        }
    }

    private String getVisiblePackages() {
@@ -1005,16 +1016,20 @@ public final class LauncherInstrumentation {
    }

    public void waitForLauncherInitialized() {
        try {
            Trace.beginSection("waitForLauncherInitialized");
            for (int i = 0; i < 100; ++i) {
            if (getTestInfo(
                    TestProtocol.REQUEST_IS_LAUNCHER_INITIALIZED).
                    getBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD)) {
                if (getTestInfo(TestProtocol.REQUEST_IS_LAUNCHER_INITIALIZED).getBoolean(
                        TestProtocol.TEST_INFO_RESPONSE_FIELD)) {
                    return;
                }
                SystemClock.sleep(100);
            }
            checkForAnomaly();
            fail("Launcher didn't initialize");
        } finally {
            Trace.endSection();
        }
    }

    public boolean isLauncherActivityStarted() {
@@ -1259,8 +1274,13 @@ public final class LauncherInstrumentation {
    }

    boolean isLauncherVisible() {
        try {
            Trace.beginSection("isLauncherVisible");
            mDevice.waitForIdle();
            return hasLauncherObject(getAnyObjectSelector());
        } finally {
            Trace.endSection();
        }
    }

    boolean isLauncherContainerVisible() {