diff --git a/protos/launcher_trace.proto b/protos/launcher_trace.proto new file mode 100644 index 0000000000..c6f3543c09 --- /dev/null +++ b/protos/launcher_trace.proto @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto2"; + +package com.android.launcher3.tracing; + +option java_multiple_files = true; + +message LauncherTraceProto { + + optional TouchInteractionServiceProto touch_interaction_service = 1; +} + +message TouchInteractionServiceProto { + + optional bool service_connected = 1; +} diff --git a/protos/launcher_trace_file.proto b/protos/launcher_trace_file.proto new file mode 100644 index 0000000000..6ce182a2ad --- /dev/null +++ b/protos/launcher_trace_file.proto @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto2"; + +import "launcher_trace.proto"; + +package com.android.launcher3.tracing; + +option java_multiple_files = true; + +/* represents a file full of launcher trace entries. + Encoded, it should start with 0x9 0x4C 0x4E 0x43 0x48 0x52 0x54 0x52 0x43 (.LNCHRTRC), such + that they can be easily identified. */ +message LauncherTraceFileProto { + + /* constant; MAGIC_NUMBER = (long) MAGIC_NUMBER_H << 32 | MagicNumber.MAGIC_NUMBER_L + (this is needed because enums have to be 32 bits and there's no nice way to put 64bit + constants into .proto files. */ + enum MagicNumber { + INVALID = 0; + MAGIC_NUMBER_L = 0x48434E4C; /* LNCH (little-endian ASCII) */ + MAGIC_NUMBER_H = 0x43525452; /* RTRC (little-endian ASCII) */ + } + + optional fixed64 magic_number = 1; /* Must be the first field, set to value in MagicNumber */ + repeated LauncherTraceEntryProto entry = 2; +} + +/* one launcher trace entry. */ +message LauncherTraceEntryProto { + /* required: elapsed realtime in nanos since boot of when this entry was logged */ + optional fixed64 elapsed_realtime_nanos = 1; + + optional LauncherTraceProto launcher = 3; +} diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java index bafb2ef7a6..e7c91955f4 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java @@ -27,6 +27,7 @@ import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_INPUT_MONITOR; import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SYSUI_PROXY; +import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_TRACING_ENABLED; import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.ACTIVITY_TYPE_ASSISTANT; import android.annotation.TargetApi; @@ -61,6 +62,8 @@ import com.android.launcher3.logging.UserEventDispatcher; import com.android.launcher3.model.AppLaunchTracker; import com.android.launcher3.provider.RestoreDbTask; import com.android.launcher3.testing.TestProtocol; +import com.android.launcher3.tracing.nano.LauncherTraceProto; +import com.android.launcher3.tracing.nano.TouchInteractionServiceProto; import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; import com.android.launcher3.util.TraceHelper; import com.android.quickstep.inputconsumers.AccessibilityInputConsumer; @@ -74,6 +77,7 @@ import com.android.quickstep.inputconsumers.ResetGestureInputConsumer; import com.android.quickstep.inputconsumers.ScreenPinnedInputConsumer; import com.android.quickstep.util.ActiveGestureLog; import com.android.quickstep.util.AssistantUtilities; +import com.android.quickstep.util.ProtoTracer; import com.android.systemui.plugins.OverscrollPlugin; import com.android.systemui.plugins.PluginListener; import com.android.systemui.shared.recents.IOverviewProxy; @@ -83,6 +87,7 @@ import com.android.systemui.shared.system.InputChannelCompat.InputEventReceiver; import com.android.systemui.shared.system.InputConsumerController; import com.android.systemui.shared.system.InputMonitorCompat; import com.android.systemui.shared.system.RecentsAnimationListener; +import com.android.systemui.shared.tracing.ProtoTraceable; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -111,7 +116,8 @@ class ArgList extends LinkedList { * Service connected by system-UI for handling touch interaction. */ @TargetApi(Build.VERSION_CODES.Q) -public class TouchInteractionService extends Service implements PluginListener { +public class TouchInteractionService extends Service implements PluginListener, + ProtoTraceable { private static final String TAG = "TouchInteractionService"; @@ -272,6 +278,7 @@ public class TouchInteractionService extends Service implements PluginListener { + + public static final MainThreadInitializedObject INSTANCE = + new MainThreadInitializedObject<>(ProtoTracer::new); + + private static final String TAG = "ProtoTracer"; + private static final long MAGIC_NUMBER_VALUE = ((long) MAGIC_NUMBER_H << 32) | MAGIC_NUMBER_L; + + private final Context mContext; + private final FrameProtoTracer mProtoTracer; + + public ProtoTracer(Context context) { + mContext = context; + mProtoTracer = new FrameProtoTracer<>(this); + } + + @Override + public File getTraceFile() { + return new File(mContext.getFilesDir(), "launcher_trace.pb"); + } + + @Override + public LauncherTraceFileProto getEncapsulatingTraceProto() { + return new LauncherTraceFileProto(); + } + + @Override + public LauncherTraceEntryProto updateBufferProto(LauncherTraceEntryProto reuseObj, + ArrayList> traceables) { + LauncherTraceEntryProto proto = reuseObj != null + ? reuseObj + : new LauncherTraceEntryProto(); + proto.elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos(); + proto.launcher = proto.launcher != null ? proto.launcher : new LauncherTraceProto(); + for (ProtoTraceable t : traceables) { + t.writeToProto(proto.launcher); + } + return proto; + } + + @Override + public byte[] serializeEncapsulatingProto(LauncherTraceFileProto encapsulatingProto, + Queue buffer) { + encapsulatingProto.magicNumber = MAGIC_NUMBER_VALUE; + encapsulatingProto.entry = buffer.toArray(new LauncherTraceEntryProto[0]); + return MessageNano.toByteArray(encapsulatingProto); + } + + @Override + public byte[] getProtoBytes(MessageNano proto) { + return MessageNano.toByteArray(proto); + } + + @Override + public int getProtoSize(MessageNano proto) { + return proto.getCachedSize(); + } + + public void start() { + mProtoTracer.start(); + } + + public void stop() { + mProtoTracer.stop(); + } + + public void add(ProtoTraceable traceable) { + mProtoTracer.add(traceable); + } + + public void remove(ProtoTraceable traceable) { + mProtoTracer.remove(traceable); + } + + public void scheduleFrameUpdate() { + mProtoTracer.scheduleFrameUpdate(); + } + + public void update() { + mProtoTracer.update(); + } +}