diff options
4 files changed, 70 insertions, 95 deletions
diff --git a/libs/WindowManager/Shell/Android.bp b/libs/WindowManager/Shell/Android.bp index 6a79bc1f46c2..54978bd4496d 100644 --- a/libs/WindowManager/Shell/Android.bp +++ b/libs/WindowManager/Shell/Android.bp @@ -125,34 +125,6 @@ prebuilt_etc { // End ProtoLog -gensrcs { - name: "wm-shell-protos", - - tools: [ - "aprotoc", - "protoc-gen-javastream", - "soong_zip", - ], - - tool_files: [ - ":libprotobuf-internal-protos", - ], - - cmd: "mkdir -p $(genDir)/$(in) " + - "&& $(location aprotoc) " + - " --plugin=$(location protoc-gen-javastream) " + - " --javastream_out=$(genDir)/$(in) " + - " -Iexternal/protobuf/src " + - " -I . " + - " $(in) " + - "&& $(location soong_zip) -jar -o $(out) -C $(genDir)/$(in) -D $(genDir)/$(in)", - - srcs: [ - "proto/**/*.proto", - ], - output_extension: "srcjar", -} - java_library { name: "WindowManager-Shell-proto", @@ -170,7 +142,6 @@ android_library { // TODO(b/168581922) protologtool do not support kotlin(*.kt) ":wm_shell-sources-kt", ":wm_shell-aidls", - ":wm-shell-protos", ], resource_dirs: [ "res", diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Tracer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Tracer.java index ba364f8a6e59..0cede902f034 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Tracer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Tracer.java @@ -18,25 +18,29 @@ package com.android.wm.shell.transition; import static android.os.Build.IS_USER; -import static com.android.wm.shell.WmShellTransitionTraceProto.MAGIC_NUMBER; -import static com.android.wm.shell.WmShellTransitionTraceProto.MAGIC_NUMBER_H; -import static com.android.wm.shell.WmShellTransitionTraceProto.MAGIC_NUMBER_L; +import static com.android.wm.shell.nano.WmShellTransitionTraceProto.MAGIC_NUMBER_H; +import static com.android.wm.shell.nano.WmShellTransitionTraceProto.MAGIC_NUMBER_L; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.SystemClock; import android.os.Trace; import android.util.Log; -import android.util.proto.ProtoOutputStream; import com.android.internal.util.TraceBuffer; +import com.android.wm.shell.nano.HandlerMapping; import com.android.wm.shell.sysui.ShellCommandHandler; +import com.google.protobuf.nano.MessageNano; + import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.Queue; /** * Helper class to collect and dump transition traces. @@ -54,8 +58,35 @@ public class Tracer implements ShellCommandHandler.ShellCommandActionHandler { private final Object mEnabledLock = new Object(); private boolean mActiveTracingEnabled = false; - private final TraceBuffer mTraceBuffer = new TraceBuffer(ALWAYS_ON_TRACING_CAPACITY, - (proto) -> handleOnEntryRemovedFromTrace(proto)); + private final TraceBuffer.ProtoProvider mProtoProvider = + new TraceBuffer.ProtoProvider<MessageNano, + com.android.wm.shell.nano.WmShellTransitionTraceProto, + com.android.wm.shell.nano.Transition>() { + @Override + public int getItemSize(MessageNano proto) { + return proto.getCachedSize(); + } + + @Override + public byte[] getBytes(MessageNano proto) { + return MessageNano.toByteArray(proto); + } + + @Override + public void write( + com.android.wm.shell.nano.WmShellTransitionTraceProto encapsulatingProto, + Queue<com.android.wm.shell.nano.Transition> buffer, OutputStream os) + throws IOException { + encapsulatingProto.transitions = buffer.toArray( + new com.android.wm.shell.nano.Transition[0]); + os.write(getBytes(encapsulatingProto)); + } + }; + private final TraceBuffer<MessageNano, + com.android.wm.shell.nano.WmShellTransitionTraceProto, + com.android.wm.shell.nano.Transition> mTraceBuffer + = new TraceBuffer(ALWAYS_ON_TRACING_CAPACITY, mProtoProvider, + (proto) -> handleOnEntryRemovedFromTrace(proto)); private final Map<Object, Runnable> mRemovedFromTraceCallbacks = new HashMap<>(); private final Map<Transitions.TransitionHandler, Integer> mHandlerIds = new HashMap<>(); @@ -78,26 +109,20 @@ public class Tracer implements ShellCommandHandler.ShellCommandActionHandler { mHandlerIds.put(handler, handlerId); } - ProtoOutputStream outputStream = new ProtoOutputStream(); - final long protoToken = - outputStream.start(com.android.wm.shell.WmShellTransitionTraceProto.TRANSITIONS); - - outputStream.write(com.android.wm.shell.Transition.ID, transitionId); - outputStream.write(com.android.wm.shell.Transition.DISPATCH_TIME_NS, - SystemClock.elapsedRealtimeNanos()); - outputStream.write(com.android.wm.shell.Transition.HANDLER, handlerId); - - outputStream.end(protoToken); + com.android.wm.shell.nano.Transition proto = new com.android.wm.shell.nano.Transition(); + proto.id = transitionId; + proto.dispatchTimeNs = SystemClock.elapsedRealtimeNanos(); + proto.handler = handlerId; final int useCountAfterAdd = mHandlerUseCountInTrace.getOrDefault(handler, 0) + 1; mHandlerUseCountInTrace.put(handler, useCountAfterAdd); - mRemovedFromTraceCallbacks.put(outputStream, () -> { + mRemovedFromTraceCallbacks.put(proto, () -> { final int useCountAfterRemove = mHandlerUseCountInTrace.get(handler) - 1; mHandlerUseCountInTrace.put(handler, useCountAfterRemove); }); - mTraceBuffer.add(outputStream); + mTraceBuffer.add(proto); } /** @@ -107,18 +132,12 @@ public class Tracer implements ShellCommandHandler.ShellCommandActionHandler { * @param playingTransitionId The id of the transition we was to merge the transition into. */ public void logMergeRequested(int mergeRequestedTransitionId, int playingTransitionId) { - ProtoOutputStream outputStream = new ProtoOutputStream(); - final long protoToken = - outputStream.start(com.android.wm.shell.WmShellTransitionTraceProto.TRANSITIONS); - - outputStream.write(com.android.wm.shell.Transition.ID, mergeRequestedTransitionId); - outputStream.write(com.android.wm.shell.Transition.MERGE_REQUEST_TIME_NS, - SystemClock.elapsedRealtimeNanos()); - outputStream.write(com.android.wm.shell.Transition.MERGED_INTO, playingTransitionId); + com.android.wm.shell.nano.Transition proto = new com.android.wm.shell.nano.Transition(); + proto.id = mergeRequestedTransitionId; + proto.mergeRequestTimeNs = SystemClock.elapsedRealtimeNanos(); + proto.mergedInto = playingTransitionId; - outputStream.end(protoToken); - - mTraceBuffer.add(outputStream); + mTraceBuffer.add(proto); } /** @@ -128,18 +147,12 @@ public class Tracer implements ShellCommandHandler.ShellCommandActionHandler { * @param playingTransitionId The id of the transition the transition was merged into. */ public void logMerged(int mergedTransitionId, int playingTransitionId) { - ProtoOutputStream outputStream = new ProtoOutputStream(); - final long protoToken = - outputStream.start(com.android.wm.shell.WmShellTransitionTraceProto.TRANSITIONS); - - outputStream.write(com.android.wm.shell.Transition.ID, mergedTransitionId); - outputStream.write( - com.android.wm.shell.Transition.MERGE_TIME_NS, SystemClock.elapsedRealtimeNanos()); - outputStream.write(com.android.wm.shell.Transition.MERGED_INTO, playingTransitionId); + com.android.wm.shell.nano.Transition proto = new com.android.wm.shell.nano.Transition(); + proto.id = mergedTransitionId; + proto.mergeTimeNs = SystemClock.elapsedRealtimeNanos(); + proto.mergedInto = playingTransitionId; - outputStream.end(protoToken); - - mTraceBuffer.add(outputStream); + mTraceBuffer.add(proto); } /** @@ -148,17 +161,11 @@ public class Tracer implements ShellCommandHandler.ShellCommandActionHandler { * @param transitionId The id of the transition that was aborted. */ public void logAborted(int transitionId) { - ProtoOutputStream outputStream = new ProtoOutputStream(); - final long protoToken = - outputStream.start(com.android.wm.shell.WmShellTransitionTraceProto.TRANSITIONS); - - outputStream.write(com.android.wm.shell.Transition.ID, transitionId); - outputStream.write( - com.android.wm.shell.Transition.ABORT_TIME_NS, SystemClock.elapsedRealtimeNanos()); - - outputStream.end(protoToken); + com.android.wm.shell.nano.Transition proto = new com.android.wm.shell.nano.Transition(); + proto.id = transitionId; + proto.abortTimeNs = SystemClock.elapsedRealtimeNanos(); - mTraceBuffer.add(outputStream); + mTraceBuffer.add(proto); } /** @@ -230,8 +237,9 @@ public class Tracer implements ShellCommandHandler.ShellCommandActionHandler { private void writeTraceToFileLocked(@Nullable PrintWriter pw, File file) { Trace.beginSection("TransitionTracer#writeTraceToFileLocked"); try { - ProtoOutputStream proto = new ProtoOutputStream(); - proto.write(MAGIC_NUMBER, MAGIC_NUMBER_VALUE); + com.android.wm.shell.nano.WmShellTransitionTraceProto proto = + new com.android.wm.shell.nano.WmShellTransitionTraceProto(); + proto.magicNumber = MAGIC_NUMBER_VALUE; writeHandlerMappingToProto(proto); int pid = android.os.Process.myPid(); LogAndPrintln.i(pw, "Writing file to " + file.getAbsolutePath() @@ -243,19 +251,21 @@ public class Tracer implements ShellCommandHandler.ShellCommandActionHandler { Trace.endSection(); } - private void writeHandlerMappingToProto(ProtoOutputStream outputStream) { + private void writeHandlerMappingToProto( + com.android.wm.shell.nano.WmShellTransitionTraceProto proto) { + ArrayList<com.android.wm.shell.nano.HandlerMapping> handlerMappings = new ArrayList<>(); for (Transitions.TransitionHandler handler : mHandlerUseCountInTrace.keySet()) { final int count = mHandlerUseCountInTrace.get(handler); if (count > 0) { - final long protoToken = outputStream.start( - com.android.wm.shell.WmShellTransitionTraceProto.HANDLER_MAPPINGS); - outputStream.write(com.android.wm.shell.HandlerMapping.ID, - mHandlerIds.get(handler)); - outputStream.write(com.android.wm.shell.HandlerMapping.NAME, - handler.getClass().getName()); - outputStream.end(protoToken); + com.android.wm.shell.nano.HandlerMapping mapping = + new com.android.wm.shell.nano.HandlerMapping(); + mapping.id = mHandlerIds.get(handler); + mapping.name = handler.getClass().getName(); + handlerMappings.add(mapping); } } + proto.handlerMappings = handlerMappings.toArray( + new com.android.wm.shell.nano.HandlerMapping[0]); } private void handleOnEntryRemovedFromTrace(Object proto) { diff --git a/packages/SystemUI/src/com/android/systemui/tracing/sysui_trace.proto b/packages/SystemUI/src/com/android/systemui/tracing/sysui_trace.proto index eb23b9d7a994..d940a6b5c460 100644 --- a/packages/SystemUI/src/com/android/systemui/tracing/sysui_trace.proto +++ b/packages/SystemUI/src/com/android/systemui/tracing/sysui_trace.proto @@ -16,8 +16,6 @@ syntax = "proto2"; -import "frameworks/base/libs/WindowManager/Shell/proto/wm_shell_trace.proto"; - package com.android.systemui.tracing; option java_multiple_files = true; @@ -25,7 +23,6 @@ option java_multiple_files = true; message SystemUiTraceProto { optional EdgeBackGestureHandlerProto edge_back_gesture_handler = 1; - optional com.android.wm.shell.WmShellTraceProto wm_shell = 2; } message EdgeBackGestureHandlerProto { diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java index e60f9b65dc1c..5144d1966222 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java @@ -362,9 +362,6 @@ public final class WMShell implements @Override public void writeToProto(SystemUiTraceProto proto) { - if (proto.wmShell == null) { - proto.wmShell = new WmShellTraceProto(); - } // Dump to WMShell proto here // TODO: Figure out how we want to synchronize while dumping to proto } |