diff options
| author | 2020-10-27 14:55:36 +0000 | |
|---|---|---|
| committer | 2020-11-13 12:31:23 +0000 | |
| commit | d7daa0bd6729039850123bd32b360d5d7ce17492 (patch) | |
| tree | c9721995f5dba1ea6c4e19c25f45bf4895acbb95 | |
| parent | 8418bef70abf31d3cbfcfa500b2e694988735557 (diff) | |
Optimized workflow for IME tracing on InputMethodManagerService side
Optimized the tracing logic for the IMMS information. The
InputMethodManagerService triggers a tracing dump through the new
method triggerManagerServiceDump, exposed by the ImeTracing
interface.
This change only covers the IMMS information. The clients and
IMS information were added on previous changes.
Bug: 154348613
Test: start IME tracing by calling "adb shell ime tracing start"
end IME tracing by calling "adb shell ime tracing stop"
pull trace using "adb pull /data/misc/wmtrace/ime_trace_managerservice.pb ime_trace_managerservice.pb"
Change-Id: Ia5fb8f47769ec8c6a1a24c18cd19952c0c550274
| -rw-r--r-- | core/java/android/util/imetracing/ImeTracingServerImpl.java | 56 | ||||
| -rw-r--r-- | services/core/java/com/android/server/inputmethod/InputMethodManagerService.java | 20 |
2 files changed, 67 insertions, 9 deletions
diff --git a/core/java/android/util/imetracing/ImeTracingServerImpl.java b/core/java/android/util/imetracing/ImeTracingServerImpl.java index d2147f8e89f3..4d4fc231f86b 100644 --- a/core/java/android/util/imetracing/ImeTracingServerImpl.java +++ b/core/java/android/util/imetracing/ImeTracingServerImpl.java @@ -19,11 +19,13 @@ package android.util.imetracing; import static android.os.Build.IS_USER; import android.inputmethodservice.AbstractInputMethodService; +import android.os.RemoteException; import android.os.ServiceManager.ServiceNotFoundException; import android.os.ShellCommand; import android.util.Log; import android.util.proto.ProtoOutputStream; import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceFileProto; +import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodManagerServiceTraceFileProto; import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodServiceTraceFileProto; import com.android.internal.annotations.GuardedBy; @@ -40,6 +42,7 @@ class ImeTracingServerImpl extends ImeTracing { private static final String TRACE_DIRNAME = "/data/misc/wmtrace/"; private static final String TRACE_FILENAME_CLIENTS = "ime_trace_clients.pb"; private static final String TRACE_FILENAME_IMS = "ime_trace_service.pb"; + private static final String TRACE_FILENAME_IMMS = "ime_trace_managerservice.pb"; private static final int BUFFER_CAPACITY = 4096 * 1024; // Needed for winscope to auto-detect the dump type. Explained further in @@ -52,11 +55,17 @@ class ImeTracingServerImpl extends ImeTracing { private static final long MAGIC_NUMBER_IMS_VALUE = ((long) InputMethodServiceTraceFileProto.MAGIC_NUMBER_H << 32) | InputMethodServiceTraceFileProto.MAGIC_NUMBER_L; + // This magic number corresponds to InputMethodManagerServiceTraceFileProto. + private static final long MAGIC_NUMBER_IMMS_VALUE = + ((long) InputMethodManagerServiceTraceFileProto.MAGIC_NUMBER_H << 32) + | InputMethodManagerServiceTraceFileProto.MAGIC_NUMBER_L; private final TraceBuffer mBufferClients; private final File mTraceFileClients; private final TraceBuffer mBufferIms; private final File mTraceFileIms; + private final TraceBuffer mBufferImms; + private final File mTraceFileImms; private final Object mEnabledLock = new Object(); @@ -65,6 +74,8 @@ class ImeTracingServerImpl extends ImeTracing { mTraceFileClients = new File(TRACE_DIRNAME + TRACE_FILENAME_CLIENTS); mBufferIms = new TraceBuffer<>(BUFFER_CAPACITY); mTraceFileIms = new File(TRACE_DIRNAME + TRACE_FILENAME_IMS); + mBufferImms = new TraceBuffer<>(BUFFER_CAPACITY); + mTraceFileImms = new File(TRACE_DIRNAME + TRACE_FILENAME_IMMS); } /** @@ -84,9 +95,11 @@ class ImeTracingServerImpl extends ImeTracing { mBufferIms.add(proto); return; case IME_TRACING_FROM_IMMS: - // TODO (b/154348613) + mBufferImms.add(proto); + return; default: // Source not recognised. + Log.w(TAG, "Request to add to buffer, but source not recognised."); } } } @@ -129,7 +142,24 @@ class ImeTracingServerImpl extends ImeTracing { @Override public void triggerManagerServiceDump(String where) { - // TODO (b/154348613) + if (!isEnabled() || !isAvailable()) { + return; + } + + synchronized (mDumpInProgressLock) { + if (mDumpInProgress) { + return; + } + mDumpInProgress = true; + } + + try { + sendToService(null, IME_TRACING_FROM_IMMS, where); + } catch (RemoteException e) { + Log.e(TAG, "Exception while sending ime-related manager service dump to server", e); + } finally { + mDumpInProgress = false; + } } private void writeTracesToFilesLocked() { @@ -142,6 +172,11 @@ class ImeTracingServerImpl extends ImeTracing { ProtoOutputStream imsProto = new ProtoOutputStream(); imsProto.write(InputMethodServiceTraceFileProto.MAGIC_NUMBER, MAGIC_NUMBER_IMS_VALUE); mBufferIms.writeTraceToFile(mTraceFileIms, imsProto); + + ProtoOutputStream immsProto = new ProtoOutputStream(); + immsProto.write(InputMethodManagerServiceTraceFileProto.MAGIC_NUMBER, + MAGIC_NUMBER_IMMS_VALUE); + mBufferImms.writeTraceToFile(mTraceFileImms, immsProto); } catch (IOException e) { Log.e(TAG, "Unable to write buffer to file", e); } @@ -161,10 +196,9 @@ class ImeTracingServerImpl extends ImeTracing { } pw.println("Starting tracing in " + TRACE_DIRNAME + ": " + TRACE_FILENAME_CLIENTS - + ", " + TRACE_FILENAME_IMS); + + ", " + TRACE_FILENAME_IMS + ", " + TRACE_FILENAME_IMMS); sEnabled = true; - mBufferClients.resetBuffer(); - mBufferIms.resetBuffer(); + resetBuffers(); } } @@ -182,11 +216,17 @@ class ImeTracingServerImpl extends ImeTracing { } pw.println("Stopping tracing and writing traces in " + TRACE_DIRNAME + ": " - + TRACE_FILENAME_CLIENTS + ", " + TRACE_FILENAME_IMS); + + TRACE_FILENAME_CLIENTS + ", " + TRACE_FILENAME_IMS + ", " + + TRACE_FILENAME_IMMS); sEnabled = false; writeTracesToFilesLocked(); - mBufferClients.resetBuffer(); - mBufferIms.resetBuffer(); + resetBuffers(); } } + + private void resetBuffers() { + mBufferClients.resetBuffer(); + mBufferIms.resetBuffer(); + mBufferImms.resetBuffer(); + } } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index c08e6a9cd8ab..30937208745a 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -40,6 +40,7 @@ import static android.server.inputmethod.InputMethodManagerServiceProto.SHOW_FOR import static android.server.inputmethod.InputMethodManagerServiceProto.SHOW_IME_WITH_HARD_KEYBOARD; import static android.server.inputmethod.InputMethodManagerServiceProto.SHOW_REQUESTED; import static android.server.inputmethod.InputMethodManagerServiceProto.SYSTEM_READY; +import static android.util.imetracing.ImeTracing.IME_TRACING_FROM_IMMS; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.INVALID_DISPLAY; @@ -141,6 +142,8 @@ import android.view.inputmethod.InputConnectionInspector.MissingMethodFlags; import android.view.inputmethod.InputMethod; import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceFileProto; import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodClientsTraceProto; +import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodManagerServiceTraceFileProto; +import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodManagerServiceTraceProto; import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodServiceTraceFileProto; import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodServiceTraceProto; import android.view.inputmethod.InputMethodInfo; @@ -3103,6 +3106,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub ResultReceiver resultReceiver) { Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMMS.showSoftInput"); int uid = Binder.getCallingUid(); + ImeTracing.getInstance().triggerManagerServiceDump( + "InputMethodManagerService#showSoftInput"); synchronized (mMethodMap) { if (!calledFromValidUserLocked()) { return false; @@ -3216,6 +3221,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub public boolean hideSoftInput(IInputMethodClient client, IBinder windowToken, int flags, ResultReceiver resultReceiver) { int uid = Binder.getCallingUid(); + ImeTracing.getInstance().triggerManagerServiceDump( + "InputMethodManagerService#hideSoftInput"); synchronized (mMethodMap) { if (!calledFromValidUserLocked()) { return false; @@ -3312,6 +3319,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub try { Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMMS.startInputOrWindowGainedFocus"); + ImeTracing.getInstance().triggerManagerServiceDump( + "InputMethodManagerService#startInputOrWindowGainedFocus"); final int callingUserId = UserHandle.getCallingUserId(); final int userId; if (attribute != null && attribute.targetInputMethodUser != null @@ -4013,7 +4022,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub @Override @GuardedBy("mMethodMap") public void startProtoDump(byte[] protoDump, int source, String where) { - if (protoDump == null) { + if (protoDump == null && source != IME_TRACING_FROM_IMMS) { // Dump not triggered from IMMS, but no proto information provided. return; } @@ -4040,6 +4049,15 @@ public class InputMethodManagerService extends IInputMethodManager.Stub proto.write(InputMethodServiceTraceProto.INPUT_METHOD_SERVICE, protoDump); proto.end(service_token); break; + case IME_TRACING_FROM_IMMS: + final long managerservice_token = + proto.start(InputMethodManagerServiceTraceFileProto.ENTRY); + proto.write(InputMethodManagerServiceTraceProto.ELAPSED_REALTIME_NANOS, + SystemClock.elapsedRealtimeNanos()); + proto.write(InputMethodManagerServiceTraceProto.WHERE, where); + dumpDebug(proto, InputMethodManagerServiceTraceProto.INPUT_METHOD_MANAGER_SERVICE); + proto.end(managerservice_token); + break; default: // Dump triggered by a source not recognised. return; |