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

Commit 535a0bc6 authored by Wu Ahan's avatar Wu Ahan Committed by Automerger Merge Worker
Browse files

Merge "Make sure the removeObservers be called correctly" into sc-v2-dev am:...

Merge "Make sure the removeObservers be called correctly" into sc-v2-dev am: 506fa0be am: ceb5b5db

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15746914

Change-Id: Id078bce060cbc021c453a3fa9635007ea6f2ef6b
parents b7eefec3 ceb5b5db
Loading
Loading
Loading
Loading
+54 −45
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import com.android.internal.util.FrameworkStatsLog;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.concurrent.TimeUnit;

/**
 * A class that allows the app to get the frame metrics from HardwareRendererObserver.
@@ -108,6 +109,7 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
    private boolean mCancelled = false;
    private FrameTrackerListener mListener;
    private boolean mTracingStarted = false;
    private Runnable mWaitForFinishTimedOut;

    private static class JankInfo {
        long frameVsyncId;
@@ -174,8 +176,8 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
            // If the surface isn't valid yet, wait until it's created.
            if (mViewRoot.getSurfaceControl().isValid()) {
                mSurfaceControl = mViewRoot.getSurfaceControl();
                mSurfaceChangedCallback = null;
            } else {
            }

            mSurfaceChangedCallback = new ViewRootImpl.SurfaceChangedCallback() {
                @Override
                public void surfaceCreated(SurfaceControl.Transaction t) {
@@ -221,7 +223,6 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
            mViewRoot.addSurfaceChangedCallback(mSurfaceChangedCallback);
        }
    }
    }

    /**
     * Begin a trace session of the CUJ.
@@ -283,10 +284,17 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
            if (mListener != null) {
                mListener.onCujEvents(mSession, ACTION_SESSION_END);
            }
        }

            // We don't remove observer here,
            // will remove it when all the frame metrics in this duration are called back.
            // See onFrameMetricsAvailable for the logic of removing the observer.
            // Let's wait for all callbacks to finish for at most a minute.
            mWaitForFinishTimedOut = () -> {
                Log.e(TAG, "force finish cuj because of time out:" + mSession.getName());
                finish(mJankInfos.size() - 1);
            };
            mHandler.postDelayed(mWaitForFinishTimedOut, TimeUnit.MINUTES.toMillis(1));
        }
    }

    /**
@@ -423,7 +431,8 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
    }

    private void finish(int indexOnOrAfterEnd) {

        mHandler.removeCallbacks(mWaitForFinishTimedOut);
        mWaitForFinishTimedOut = null;
        mMetricsFinalized = true;

        // The tracing has been ended, remove the observer, see if need to trigger perfetto.
@@ -509,7 +518,7 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
            }
        }
        if (DEBUG) {
            Log.i(TAG, "FrameTracker: CUJ=" + mSession.getName()
            Log.i(TAG, "finish: CUJ=" + mSession.getName()
                    + " (" + mBeginVsyncId + "," + mEndVsyncId + ")"
                    + " totalFrames=" + totalFramesCount
                    + " missedAppFrames=" + missedAppFramesCount