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

Commit 539f5778 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add "cmd window trace save-for-bugreport"" into sc-dev am: 42746017

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13632997

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Iead541dd8d001c168dcd8b2a43d2e1c58e5cedc6
parents 37f50e8a 42746017
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -359,18 +359,6 @@ public class BaseProtoLogImpl {
                + "\nLogging definitions loaded: " + mViewerConfig.knownViewerStringsNumber();
    }

    /**
     * Writes the log buffer to a new file for the bugreport.
     *
     * This method is synchronized with {@code #startProtoLog(PrintWriter)} and
     * {@link #stopProtoLog(PrintWriter, boolean)}.
     */
    public void writeProtoLogToFile() {
        synchronized (mProtoLogEnabledLock) {
            writeProtoLogToFileLocked();
        }
    }

    private void writeProtoLogToFileLocked() {
        try {
            long offset =
+0 −9
Original line number Diff line number Diff line
@@ -273,7 +273,6 @@ import android.window.TaskSnapshot;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.BackgroundThread;
import com.android.internal.os.IResultReceiver;
import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.policy.IShortcutService;
@@ -529,14 +528,6 @@ public class WindowManagerService extends IWindowManager.Stub
        @Override
        public void dumpCritical(FileDescriptor fd, PrintWriter pw, String[] args,
                boolean asProto) {
            // Bugreport dumps the trace 2x, 1x as proto and 1x as text. Save file to disk only 1x.
            if (asProto && mWindowTracing.isEnabled()) {
                mWindowTracing.stopTrace(null, false /* writeToFile */);
                BackgroundThread.getHandler().post(() -> {
                    mWindowTracing.writeTraceToFile();
                    mWindowTracing.startTrace(null);
                });
            }
            doDump(fd, pw, new String[] {"-a"}, asProto);
        }

+31 −26
Original line number Diff line number Diff line
@@ -114,15 +114,6 @@ class WindowTracing {
     * @param pw Print writer
     */
    void stopTrace(@Nullable PrintWriter pw) {
        stopTrace(pw, true /* writeToFile */);
    }

    /**
     * Stops the trace
     * @param pw Print writer
     * @param writeToFile If the current buffer should be written to disk or not
     */
    void stopTrace(@Nullable PrintWriter pw, boolean writeToFile) {
        if (IS_USER) {
            logAndPrintln(pw, "Error: Tracing is not supported on user builds.");
            return;
@@ -135,12 +126,35 @@ class WindowTracing {
                logAndPrintln(pw, "ERROR: tracing was re-enabled while waiting for flush.");
                throw new IllegalStateException("tracing enabled while waiting for flush.");
            }
            if (writeToFile) {
            writeTraceToFileLocked();
            logAndPrintln(pw, "Trace written to " + mTraceFile + ".");
        }
        ProtoLogImpl.getSingleInstance().stopProtoLog(pw, true);
    }

    /**
     * Stops the trace and write the current buffer to disk then restart, if it's already running.
     * @param pw Print writer
     */
    void saveForBugreport(@Nullable PrintWriter pw) {
        if (IS_USER) {
            logAndPrintln(pw, "Error: Tracing is not supported on user builds.");
            return;
        }
        synchronized (mEnabledLock) {
            if (!mEnabled) {
                return;
            }
            mEnabled = mEnabledLockFree = false;
            logAndPrintln(pw, "Stop tracing to " + mTraceFile + ". Waiting for traces to flush.");
            writeTraceToFileLocked();
            logAndPrintln(pw, "Trace written to " + mTraceFile + ".");
            ProtoLogImpl.getSingleInstance().stopProtoLog(pw, true);
            logAndPrintln(pw, "Start tracing to " + mTraceFile + ".");
            mBuffer.resetBuffer();
            mEnabled = mEnabledLockFree = true;
            ProtoLogImpl.getSingleInstance().startProtoLog(pw);
        }
        ProtoLogImpl.getSingleInstance().stopProtoLog(pw, writeToFile);
    }

    private void setLogLevel(@WindowTraceLogLevel int logLevel, PrintWriter pw) {
@@ -188,6 +202,9 @@ class WindowTracing {
            case "stop":
                stopTrace(pw);
                return 0;
            case "save-for-bugreport":
                saveForBugreport(pw);
                return 0;
            case "status":
                logAndPrintln(pw, getStatus());
                return 0;
@@ -230,6 +247,7 @@ class WindowTracing {
                pw.println("Window manager trace options:");
                pw.println("  start: Start logging");
                pw.println("  stop: Stop logging");
                pw.println("  save-for-bugreport: Save logging data to file if it's running.");
                pw.println("  frame: Log trace once per frame");
                pw.println("  transaction: Log each transaction");
                pw.println("  size: Set the maximum log size (in KB)");
@@ -316,19 +334,6 @@ class WindowTracing {
        }
    }

    /**
     * Writes the trace buffer to new file for the bugreport.
     *
     * This method is synchronized with {@code #startTrace(PrintWriter)} and
     * {@link #stopTrace(PrintWriter)}.
     */
    void writeTraceToFile() {
        synchronized (mEnabledLock) {
            writeTraceToFileLocked();
        }
        ProtoLogImpl.getSingleInstance().writeProtoLogToFile();
    }

    private void logAndPrintln(@Nullable PrintWriter pw, String msg) {
        Log.i(TAG, msg);
        if (pw != null) {