From 541c4b6021228ed0f8256e91462fa49d50797cc9 Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Wed, 3 May 2023 13:27:55 +0000 Subject: [PATCH] Add real to elapsed offset to shell transition trace So the entries can be mapped to the respective unix timestamps for Winscope. Test: Capture trace from winscope and make sure timeline is properly synchronized Bug: 277181336 Change-Id: I2478b3ce98d2ffe639276715b3c3984a4e450152 --- .../Shell/proto/wm_shell_transition_trace.proto | 3 +++ .../Shell/src/com/android/wm/shell/transition/Tracer.java | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/WindowManager/Shell/proto/wm_shell_transition_trace.proto b/libs/WindowManager/Shell/proto/wm_shell_transition_trace.proto index 6e0110193a057..c82a70c9a44e4 100644 --- a/libs/WindowManager/Shell/proto/wm_shell_transition_trace.proto +++ b/libs/WindowManager/Shell/proto/wm_shell_transition_trace.proto @@ -37,6 +37,9 @@ message WmShellTransitionTraceProto { required fixed64 magic_number = 1; repeated Transition transitions = 2; repeated HandlerMapping handlerMappings = 3; + /* offset between real-time clock and elapsed time clock in nanoseconds. + Calculated as: 1000000 * System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() */ + optional fixed64 real_to_elapsed_time_offset_nanos = 4; } message Transition { 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 0cede902f0349..e27e4f9904078 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 @@ -28,7 +28,6 @@ import android.os.Trace; import android.util.Log; 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; @@ -41,6 +40,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Queue; +import java.util.concurrent.TimeUnit; /** * Helper class to collect and dump transition traces. @@ -241,6 +241,10 @@ public class Tracer implements ShellCommandHandler.ShellCommandActionHandler { new com.android.wm.shell.nano.WmShellTransitionTraceProto(); proto.magicNumber = MAGIC_NUMBER_VALUE; writeHandlerMappingToProto(proto); + long timeOffsetNs = + TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()) + - SystemClock.elapsedRealtimeNanos(); + proto.realToElapsedTimeOffsetNanos = timeOffsetNs; int pid = android.os.Process.myPid(); LogAndPrintln.i(pw, "Writing file to " + file.getAbsolutePath() + " from process " + pid);