From 1a761a62dc3b290079daece9a25b85d7e7d36db6 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Mon, 15 Jul 2024 20:26:17 +0000 Subject: Add tracepoints when clients use vsyncids from a different choreographer Clients may get a stale vysnc id if the callbacks are set on a different choregrapher than the one they query for vsyncids. This cl tracks the callbacks and adds a trace point when a stale vsyncid is retrieved. Flag: EXEMPT logging Bug: 343039961 Test: perfetto traces Change-Id: Icbfd5a93267cd4c7e355f34bd544b436bcf8f2c7 --- core/java/android/view/Choreographer.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/java/android/view/Choreographer.java b/core/java/android/view/Choreographer.java index f0e673b3e3ac..7e247493e35c 100644 --- a/core/java/android/view/Choreographer.java +++ b/core/java/android/view/Choreographer.java @@ -41,6 +41,7 @@ import android.util.TimeUtils; import android.view.animation.AnimationUtils; import java.io.PrintWriter; +import java.util.Locale; /** * Coordinates the timing of animations, input and drawing. @@ -200,6 +201,7 @@ public final class Choreographer { private final DisplayEventReceiver.VsyncEventData mLastVsyncEventData = new DisplayEventReceiver.VsyncEventData(); private final FrameData mFrameData = new FrameData(); + private volatile boolean mInDoFrameCallback = false; /** * Contains information about the current frame for jank-tracking, @@ -818,6 +820,11 @@ public final class Choreographer { * @hide */ public long getVsyncId() { + if (!mInDoFrameCallback && Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) { + String message = String.format(Locale.getDefault(), "unsync-vsync-id=%d isSfChoreo=%s", + mLastVsyncEventData.preferredFrameTimeline().vsyncId, this == getSfInstance()); + Trace.instant(Trace.TRACE_TAG_VIEW, message); + } return mLastVsyncEventData.preferredFrameTimeline().vsyncId; } @@ -853,6 +860,7 @@ public final class Choreographer { if (Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) { Trace.traceBegin( Trace.TRACE_TAG_VIEW, "Choreographer#doFrame " + timeline.mVsyncId); + mInDoFrameCallback = true; } synchronized (mLock) { if (!mFrameScheduled) { @@ -947,6 +955,7 @@ public final class Choreographer { doCallbacks(Choreographer.CALLBACK_COMMIT, frameIntervalNanos); } finally { AnimationUtils.unlockAnimationClock(); + mInDoFrameCallback = false; if (resynced) { Trace.traceEnd(Trace.TRACE_TAG_VIEW); } -- cgit v1.2.3-59-g8ed1b