Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e941d4e5 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Only start tracing in the next frame

In order to match tracing markers with the metrics, we should start
the tracing marker at the beginning of the next frame, as this is
also the point in time where we start counting janky frames.

Test: Take trace, inspect
Bug: 185902609
Change-Id: I2ec70b3fc2d3236bc24891ef698fdd7ac2917b01
parent 1abb5dc2
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
    private boolean mMetricsFinalized;
    private boolean mCancelled = false;
    private FrameTrackerListener mListener;
    private boolean mTracingStarted = false;

    private static class JankInfo {
        long frameVsyncId;
@@ -207,7 +208,15 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
    public synchronized void begin() {
        mBeginVsyncId = mChoreographer.getVsyncId() + 1;
        mSession.setTimeStamp(System.nanoTime());
        mChoreographer.mChoreographer.postCallback(Choreographer.CALLBACK_INPUT, () -> {
            synchronized (FrameTracker.this) {
                if (mCancelled || mEndVsyncId != INVALID_ID) {
                    return;
                }
                mTracingStarted = true;
                Trace.beginAsyncSection(mSession.getName(), (int) mBeginVsyncId);
            }
        }, null);
        mRendererWrapper.addObserver(mObserver);
        if (DEBUG) {
            Log.d(TAG, "begin: " + mSession.getName() + ", begin=" + mBeginVsyncId);
@@ -255,7 +264,7 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
     */
    public synchronized void cancel(@Reasons int reason) {
        // We don't need to end the trace section if it never begun.
        if (mBeginVsyncId != INVALID_ID) {
        if (mTracingStarted) {
            Trace.endAsyncSection(mSession.getName(), (int) mBeginVsyncId);
        }
        mCancelled = true;
+6 −0
Original line number Diff line number Diff line
@@ -79,6 +79,12 @@ import java.util.concurrent.TimeUnit;

/**
 * This class let users to begin and end the always on tracing mechanism.
 *
 * Enabling for local development:
 *
 * adb shell device_config put interaction_jank_monitor enabled true
 * adb shell device_config put interaction_jank_monitor sampling_interval 1
 *
 * @hide
 */
public class InteractionJankMonitor {