Loading core/java/android/util/imetracing/ImeTracing.java +10 −13 Original line number Original line Diff line number Diff line Loading @@ -129,6 +129,16 @@ public abstract class ImeTracing { */ */ public abstract void triggerManagerServiceDump(String where); public abstract void triggerManagerServiceDump(String where); /** * Being called while taking a bugreport so that tracing files can be included in the bugreport * when the IME tracing is running. Does nothing otherwise. * * @param pw Print writer */ public void saveForBugreport(@Nullable PrintWriter pw) { // does nothing by default. } /** /** * Sets whether ime tracing is enabled. * Sets whether ime tracing is enabled. * * Loading @@ -152,11 +162,6 @@ public abstract class ImeTracing { return mService != null; return mService != null; } } /** * Writes the current tracing data to the specific output proto file. */ public abstract void writeTracesToFiles(); /** /** * Starts a new IME trace if one is not already started. * Starts a new IME trace if one is not already started. * * Loading @@ -171,14 +176,6 @@ public abstract class ImeTracing { */ */ public abstract void stopTrace(@Nullable PrintWriter pw); public abstract void stopTrace(@Nullable PrintWriter pw); /** * Stops the IME trace if one was previously started. * * @param pw Print writer * @param writeToFile If the current buffer should be written to disk or not */ public abstract void stopTrace(@Nullable PrintWriter pw, boolean writeToFile); private static boolean isSystemProcess() { private static boolean isSystemProcess() { return ActivityThread.isSystem(); return ActivityThread.isSystem(); } } Loading core/java/android/util/imetracing/ImeTracingClientImpl.java +0 −8 Original line number Original line Diff line number Diff line Loading @@ -98,10 +98,6 @@ class ImeTracingClientImpl extends ImeTracing { // Intentionally left empty, this is implemented in ImeTracingServerImpl // Intentionally left empty, this is implemented in ImeTracingServerImpl } } @Override public void writeTracesToFiles() { } @Override @Override public void startTrace(PrintWriter pw) { public void startTrace(PrintWriter pw) { } } Loading @@ -109,8 +105,4 @@ class ImeTracingClientImpl extends ImeTracing { @Override @Override public void stopTrace(PrintWriter pw) { public void stopTrace(PrintWriter pw) { } } @Override public void stopTrace(PrintWriter pw, boolean writeToFile) { } } } core/java/android/util/imetracing/ImeTracingServerImpl.java +28 −16 Original line number Original line Diff line number Diff line Loading @@ -139,14 +139,6 @@ class ImeTracingServerImpl extends ImeTracing { } } } } @GuardedBy("mEnabledLock") @Override public void writeTracesToFiles() { synchronized (mEnabledLock) { writeTracesToFilesLocked(); } } private void writeTracesToFilesLocked() { private void writeTracesToFilesLocked() { try { try { ProtoOutputStream clientsProto = new ProtoOutputStream(); ProtoOutputStream clientsProto = new ProtoOutputStream(); Loading Loading @@ -192,12 +184,6 @@ class ImeTracingServerImpl extends ImeTracing { @Override @Override public void stopTrace(@Nullable PrintWriter pw) { public void stopTrace(@Nullable PrintWriter pw) { stopTrace(pw, true /* writeToFile */); } @GuardedBy("mEnabledLock") @Override public void stopTrace(@Nullable PrintWriter pw, boolean writeToFile) { if (IS_USER) { if (IS_USER) { Log.w(TAG, "Warn: Tracing is not supported on user builds."); Log.w(TAG, "Warn: Tracing is not supported on user builds."); return; return; Loading @@ -213,10 +199,36 @@ class ImeTracingServerImpl extends ImeTracing { + TRACE_FILENAME_CLIENTS + ", " + TRACE_FILENAME_IMS + ", " + TRACE_FILENAME_CLIENTS + ", " + TRACE_FILENAME_IMS + ", " + TRACE_FILENAME_IMMS); + TRACE_FILENAME_IMMS); sEnabled = false; sEnabled = false; if (writeToFile) { writeTracesToFilesLocked(); writeTracesToFilesLocked(); } } } } /** * {@inheritDoc} */ @Override public void saveForBugreport(@Nullable PrintWriter pw) { if (IS_USER) { return; } synchronized (mEnabledLock) { if (!isAvailable() || !isEnabled()) { return; } // Temporarily stop accepting logs from trace event providers. There is a small chance // that we may drop some trace events while writing the file, but we currently need to // live with that. Note that addToBuffer() also has a bug that it doesn't do // read-acquire so flipping sEnabled here doesn't even guarantee that addToBuffer() will // temporarily stop accepting incoming events... // TODO(b/175761228): Implement atomic snapshot to avoid downtime. // TODO(b/175761228): Fix synchronization around sEnabled. sEnabled = false; logAndPrintln(pw, "Writing traces in " + TRACE_DIRNAME + ": " + TRACE_FILENAME_CLIENTS + ", " + TRACE_FILENAME_IMS + ", " + TRACE_FILENAME_IMMS); writeTracesToFilesLocked(); sEnabled = true; } } } private void resetBuffers() { private void resetBuffers() { Loading services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +7 −14 Original line number Original line Diff line number Diff line Loading @@ -175,7 +175,6 @@ import com.android.internal.inputmethod.StartInputReason; import com.android.internal.inputmethod.UnbindReason; import com.android.internal.inputmethod.UnbindReason; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.internal.notification.SystemNotificationChannels; import com.android.internal.notification.SystemNotificationChannels; import com.android.internal.os.BackgroundThread; import com.android.internal.os.HandlerCaller; import com.android.internal.os.HandlerCaller; import com.android.internal.os.SomeArgs; import com.android.internal.os.SomeArgs; import com.android.internal.os.TransferPipe; import com.android.internal.os.TransferPipe; Loading Loading @@ -5230,15 +5229,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; if (ArrayUtils.contains(args, PROTO_ARG)) { if (ArrayUtils.contains(args, PROTO_ARG)) { final ImeTracing imeTracing = ImeTracing.getInstance(); if (imeTracing.isEnabled()) { imeTracing.stopTrace(null, false /* writeToFile */); BackgroundThread.getHandler().post(() -> { imeTracing.writeTracesToFiles(); imeTracing.startTrace(null); }); } final ProtoOutputStream proto = new ProtoOutputStream(fd); final ProtoOutputStream proto = new ProtoOutputStream(fd); dumpDebug(proto, InputMethodManagerServiceTraceProto.INPUT_METHOD_MANAGER_SERVICE); dumpDebug(proto, InputMethodManagerServiceTraceProto.INPUT_METHOD_MANAGER_SERVICE); proto.flush(); proto.flush(); Loading Loading @@ -5816,7 +5806,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } /** /** * Handles {@code adb shell ime tracing start/stop}. * Handles {@code adb shell cmd input_method tracing start/stop/save-for-bugreport}. * @param shellCommand {@link ShellCommand} object that is handling this command. * @param shellCommand {@link ShellCommand} object that is handling this command. * @return Exit code of the command. * @return Exit code of the command. */ */ Loading @@ -5828,16 +5818,19 @@ public class InputMethodManagerService extends IInputMethodManager.Stub switch (cmd) { switch (cmd) { case "start": case "start": ImeTracing.getInstance().getInstance().startTrace(pw); ImeTracing.getInstance().getInstance().startTrace(pw); break; break; // proceed to the next step to update the IME client processes. case "stop": case "stop": ImeTracing.getInstance().stopTrace(pw); ImeTracing.getInstance().stopTrace(pw); break; break; // proceed to the next step to update the IME client processes. case "save-for-bugreport": ImeTracing.getInstance().saveForBugreport(pw); return ShellCommandResult.SUCCESS; // no need to update the IME client processes. default: default: pw.println("Unknown command: " + cmd); pw.println("Unknown command: " + cmd); pw.println("Input method trace options:"); pw.println("Input method trace options:"); pw.println(" start: Start tracing"); pw.println(" start: Start tracing"); pw.println(" stop: Stop tracing"); pw.println(" stop: Stop tracing"); return ShellCommandResult.FAILURE; return ShellCommandResult.FAILURE; // no need to update the IME client processes. } } boolean isImeTraceEnabled = ImeTracing.getInstance().isEnabled(); boolean isImeTraceEnabled = ImeTracing.getInstance().isEnabled(); ArrayMap<IBinder, ClientState> clients; ArrayMap<IBinder, ClientState> clients; Loading Loading
core/java/android/util/imetracing/ImeTracing.java +10 −13 Original line number Original line Diff line number Diff line Loading @@ -129,6 +129,16 @@ public abstract class ImeTracing { */ */ public abstract void triggerManagerServiceDump(String where); public abstract void triggerManagerServiceDump(String where); /** * Being called while taking a bugreport so that tracing files can be included in the bugreport * when the IME tracing is running. Does nothing otherwise. * * @param pw Print writer */ public void saveForBugreport(@Nullable PrintWriter pw) { // does nothing by default. } /** /** * Sets whether ime tracing is enabled. * Sets whether ime tracing is enabled. * * Loading @@ -152,11 +162,6 @@ public abstract class ImeTracing { return mService != null; return mService != null; } } /** * Writes the current tracing data to the specific output proto file. */ public abstract void writeTracesToFiles(); /** /** * Starts a new IME trace if one is not already started. * Starts a new IME trace if one is not already started. * * Loading @@ -171,14 +176,6 @@ public abstract class ImeTracing { */ */ public abstract void stopTrace(@Nullable PrintWriter pw); public abstract void stopTrace(@Nullable PrintWriter pw); /** * Stops the IME trace if one was previously started. * * @param pw Print writer * @param writeToFile If the current buffer should be written to disk or not */ public abstract void stopTrace(@Nullable PrintWriter pw, boolean writeToFile); private static boolean isSystemProcess() { private static boolean isSystemProcess() { return ActivityThread.isSystem(); return ActivityThread.isSystem(); } } Loading
core/java/android/util/imetracing/ImeTracingClientImpl.java +0 −8 Original line number Original line Diff line number Diff line Loading @@ -98,10 +98,6 @@ class ImeTracingClientImpl extends ImeTracing { // Intentionally left empty, this is implemented in ImeTracingServerImpl // Intentionally left empty, this is implemented in ImeTracingServerImpl } } @Override public void writeTracesToFiles() { } @Override @Override public void startTrace(PrintWriter pw) { public void startTrace(PrintWriter pw) { } } Loading @@ -109,8 +105,4 @@ class ImeTracingClientImpl extends ImeTracing { @Override @Override public void stopTrace(PrintWriter pw) { public void stopTrace(PrintWriter pw) { } } @Override public void stopTrace(PrintWriter pw, boolean writeToFile) { } } }
core/java/android/util/imetracing/ImeTracingServerImpl.java +28 −16 Original line number Original line Diff line number Diff line Loading @@ -139,14 +139,6 @@ class ImeTracingServerImpl extends ImeTracing { } } } } @GuardedBy("mEnabledLock") @Override public void writeTracesToFiles() { synchronized (mEnabledLock) { writeTracesToFilesLocked(); } } private void writeTracesToFilesLocked() { private void writeTracesToFilesLocked() { try { try { ProtoOutputStream clientsProto = new ProtoOutputStream(); ProtoOutputStream clientsProto = new ProtoOutputStream(); Loading Loading @@ -192,12 +184,6 @@ class ImeTracingServerImpl extends ImeTracing { @Override @Override public void stopTrace(@Nullable PrintWriter pw) { public void stopTrace(@Nullable PrintWriter pw) { stopTrace(pw, true /* writeToFile */); } @GuardedBy("mEnabledLock") @Override public void stopTrace(@Nullable PrintWriter pw, boolean writeToFile) { if (IS_USER) { if (IS_USER) { Log.w(TAG, "Warn: Tracing is not supported on user builds."); Log.w(TAG, "Warn: Tracing is not supported on user builds."); return; return; Loading @@ -213,10 +199,36 @@ class ImeTracingServerImpl extends ImeTracing { + TRACE_FILENAME_CLIENTS + ", " + TRACE_FILENAME_IMS + ", " + TRACE_FILENAME_CLIENTS + ", " + TRACE_FILENAME_IMS + ", " + TRACE_FILENAME_IMMS); + TRACE_FILENAME_IMMS); sEnabled = false; sEnabled = false; if (writeToFile) { writeTracesToFilesLocked(); writeTracesToFilesLocked(); } } } } /** * {@inheritDoc} */ @Override public void saveForBugreport(@Nullable PrintWriter pw) { if (IS_USER) { return; } synchronized (mEnabledLock) { if (!isAvailable() || !isEnabled()) { return; } // Temporarily stop accepting logs from trace event providers. There is a small chance // that we may drop some trace events while writing the file, but we currently need to // live with that. Note that addToBuffer() also has a bug that it doesn't do // read-acquire so flipping sEnabled here doesn't even guarantee that addToBuffer() will // temporarily stop accepting incoming events... // TODO(b/175761228): Implement atomic snapshot to avoid downtime. // TODO(b/175761228): Fix synchronization around sEnabled. sEnabled = false; logAndPrintln(pw, "Writing traces in " + TRACE_DIRNAME + ": " + TRACE_FILENAME_CLIENTS + ", " + TRACE_FILENAME_IMS + ", " + TRACE_FILENAME_IMMS); writeTracesToFilesLocked(); sEnabled = true; } } } private void resetBuffers() { private void resetBuffers() { Loading
services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +7 −14 Original line number Original line Diff line number Diff line Loading @@ -175,7 +175,6 @@ import com.android.internal.inputmethod.StartInputReason; import com.android.internal.inputmethod.UnbindReason; import com.android.internal.inputmethod.UnbindReason; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.internal.notification.SystemNotificationChannels; import com.android.internal.notification.SystemNotificationChannels; import com.android.internal.os.BackgroundThread; import com.android.internal.os.HandlerCaller; import com.android.internal.os.HandlerCaller; import com.android.internal.os.SomeArgs; import com.android.internal.os.SomeArgs; import com.android.internal.os.TransferPipe; import com.android.internal.os.TransferPipe; Loading Loading @@ -5230,15 +5229,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; if (ArrayUtils.contains(args, PROTO_ARG)) { if (ArrayUtils.contains(args, PROTO_ARG)) { final ImeTracing imeTracing = ImeTracing.getInstance(); if (imeTracing.isEnabled()) { imeTracing.stopTrace(null, false /* writeToFile */); BackgroundThread.getHandler().post(() -> { imeTracing.writeTracesToFiles(); imeTracing.startTrace(null); }); } final ProtoOutputStream proto = new ProtoOutputStream(fd); final ProtoOutputStream proto = new ProtoOutputStream(fd); dumpDebug(proto, InputMethodManagerServiceTraceProto.INPUT_METHOD_MANAGER_SERVICE); dumpDebug(proto, InputMethodManagerServiceTraceProto.INPUT_METHOD_MANAGER_SERVICE); proto.flush(); proto.flush(); Loading Loading @@ -5816,7 +5806,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } /** /** * Handles {@code adb shell ime tracing start/stop}. * Handles {@code adb shell cmd input_method tracing start/stop/save-for-bugreport}. * @param shellCommand {@link ShellCommand} object that is handling this command. * @param shellCommand {@link ShellCommand} object that is handling this command. * @return Exit code of the command. * @return Exit code of the command. */ */ Loading @@ -5828,16 +5818,19 @@ public class InputMethodManagerService extends IInputMethodManager.Stub switch (cmd) { switch (cmd) { case "start": case "start": ImeTracing.getInstance().getInstance().startTrace(pw); ImeTracing.getInstance().getInstance().startTrace(pw); break; break; // proceed to the next step to update the IME client processes. case "stop": case "stop": ImeTracing.getInstance().stopTrace(pw); ImeTracing.getInstance().stopTrace(pw); break; break; // proceed to the next step to update the IME client processes. case "save-for-bugreport": ImeTracing.getInstance().saveForBugreport(pw); return ShellCommandResult.SUCCESS; // no need to update the IME client processes. default: default: pw.println("Unknown command: " + cmd); pw.println("Unknown command: " + cmd); pw.println("Input method trace options:"); pw.println("Input method trace options:"); pw.println(" start: Start tracing"); pw.println(" start: Start tracing"); pw.println(" stop: Stop tracing"); pw.println(" stop: Stop tracing"); return ShellCommandResult.FAILURE; return ShellCommandResult.FAILURE; // no need to update the IME client processes. } } boolean isImeTraceEnabled = ImeTracing.getInstance().isEnabled(); boolean isImeTraceEnabled = ImeTracing.getInstance().isEnabled(); ArrayMap<IBinder, ClientState> clients; ArrayMap<IBinder, ClientState> clients; Loading