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

This commit is contained in:
TreeHugger Robot
2021-03-11 22:18:16 +00:00
committed by Android (Google) Code Review
3 changed files with 32 additions and 48 deletions

View File

@@ -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 =

View File

@@ -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);
}

View File

@@ -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 + ".");
}
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) {