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

Commit 9e260468 authored by Nataniel Borges's avatar Nataniel Borges
Browse files

Add systrace dump to the critical section of the bugreport

Use a separate thread to write the data to disk

Test: Flash a device. Enable logging. Perform some actions. Trigger a
bug report. Check the the WM trace is included in the bugreport

Change-Id: I102bc4afab5efff361633d75c09af1df4a11812e
parent 01dd1a23
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -231,6 +231,7 @@ import android.view.WindowManagerPolicyConstants.PointerEventListener;

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;
@@ -410,6 +411,14 @@ 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);
        }

@@ -6176,9 +6185,6 @@ public class WindowManagerService extends IWindowManager.Stub
                return;
            } else if ("trace".equals(cmd)) {
                dumpTraceStatus(pw);
                synchronized (mGlobalLock) {
                    mWindowTracing.writeTraceToFile();
                }
                return;
            } else {
                // Dumping a single name?
+17 −2
Original line number Diff line number Diff line
@@ -100,7 +100,20 @@ class WindowTracing {
        }
    }

    /**
     * Stops the trace and write the current buffer to disk
     * @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;
@@ -113,10 +126,12 @@ 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 + ".");
            }
        }
    }

    private void setLogLevel(@WindowTraceLogLevel int logLevel, PrintWriter pw) {
        logAndPrintln(pw, "Setting window tracing log level to " + logLevel);