Merge "Make sure the removeObservers be called correctly" into sc-v2-dev
This commit is contained in:
@@ -51,6 +51,7 @@ import com.android.internal.util.FrameworkStatsLog;
|
|||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that allows the app to get the frame metrics from HardwareRendererObserver.
|
* 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 boolean mCancelled = false;
|
||||||
private FrameTrackerListener mListener;
|
private FrameTrackerListener mListener;
|
||||||
private boolean mTracingStarted = false;
|
private boolean mTracingStarted = false;
|
||||||
|
private Runnable mWaitForFinishTimedOut;
|
||||||
|
|
||||||
private static class JankInfo {
|
private static class JankInfo {
|
||||||
long frameVsyncId;
|
long frameVsyncId;
|
||||||
@@ -174,52 +176,51 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
|
|||||||
// If the surface isn't valid yet, wait until it's created.
|
// If the surface isn't valid yet, wait until it's created.
|
||||||
if (mViewRoot.getSurfaceControl().isValid()) {
|
if (mViewRoot.getSurfaceControl().isValid()) {
|
||||||
mSurfaceControl = mViewRoot.getSurfaceControl();
|
mSurfaceControl = mViewRoot.getSurfaceControl();
|
||||||
mSurfaceChangedCallback = null;
|
}
|
||||||
} else {
|
|
||||||
mSurfaceChangedCallback = new ViewRootImpl.SurfaceChangedCallback() {
|
mSurfaceChangedCallback = new ViewRootImpl.SurfaceChangedCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void surfaceCreated(SurfaceControl.Transaction t) {
|
public void surfaceCreated(SurfaceControl.Transaction t) {
|
||||||
synchronized (FrameTracker.this) {
|
synchronized (FrameTracker.this) {
|
||||||
if (mSurfaceControl == null) {
|
if (mSurfaceControl == null) {
|
||||||
mSurfaceControl = mViewRoot.getSurfaceControl();
|
mSurfaceControl = mViewRoot.getSurfaceControl();
|
||||||
if (mBeginVsyncId != INVALID_ID) {
|
if (mBeginVsyncId != INVALID_ID) {
|
||||||
mSurfaceControlWrapper.addJankStatsListener(
|
mSurfaceControlWrapper.addJankStatsListener(
|
||||||
FrameTracker.this, mSurfaceControl);
|
FrameTracker.this, mSurfaceControl);
|
||||||
postTraceStartMarker();
|
postTraceStartMarker();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceReplaced(SurfaceControl.Transaction t) {
|
public void surfaceReplaced(SurfaceControl.Transaction t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceDestroyed() {
|
public void surfaceDestroyed() {
|
||||||
|
|
||||||
// Wait a while to give the system a chance for the remaining
|
// Wait a while to give the system a chance for the remaining
|
||||||
// frames to arrive, then force finish the session.
|
// frames to arrive, then force finish the session.
|
||||||
mHandler.postDelayed(() -> {
|
mHandler.postDelayed(() -> {
|
||||||
synchronized (FrameTracker.this) {
|
synchronized (FrameTracker.this) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "surfaceDestroyed: " + mSession.getName()
|
Log.d(TAG, "surfaceDestroyed: " + mSession.getName()
|
||||||
+ ", finalized=" + mMetricsFinalized
|
+ ", finalized=" + mMetricsFinalized
|
||||||
+ ", info=" + mJankInfos.size()
|
+ ", info=" + mJankInfos.size()
|
||||||
+ ", vsync=" + mBeginVsyncId + "-" + mEndVsyncId);
|
+ ", vsync=" + mBeginVsyncId + "-" + mEndVsyncId);
|
||||||
}
|
|
||||||
if (!mMetricsFinalized) {
|
|
||||||
end(REASON_END_SURFACE_DESTROYED);
|
|
||||||
finish(mJankInfos.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 50);
|
if (!mMetricsFinalized) {
|
||||||
}
|
end(REASON_END_SURFACE_DESTROYED);
|
||||||
};
|
finish(mJankInfos.size() - 1);
|
||||||
// This callback has a reference to FrameTracker,
|
}
|
||||||
// remember to remove it to avoid leakage.
|
}
|
||||||
mViewRoot.addSurfaceChangedCallback(mSurfaceChangedCallback);
|
}, 50);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// This callback has a reference to FrameTracker,
|
||||||
|
// remember to remove it to avoid leakage.
|
||||||
|
mViewRoot.addSurfaceChangedCallback(mSurfaceChangedCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,10 +284,17 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
|
|||||||
if (mListener != null) {
|
if (mListener != null) {
|
||||||
mListener.onCujEvents(mSession, ACTION_SESSION_END);
|
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));
|
||||||
}
|
}
|
||||||
// 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.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -423,7 +431,8 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void finish(int indexOnOrAfterEnd) {
|
private void finish(int indexOnOrAfterEnd) {
|
||||||
|
mHandler.removeCallbacks(mWaitForFinishTimedOut);
|
||||||
|
mWaitForFinishTimedOut = null;
|
||||||
mMetricsFinalized = true;
|
mMetricsFinalized = true;
|
||||||
|
|
||||||
// The tracing has been ended, remove the observer, see if need to trigger perfetto.
|
// 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) {
|
if (DEBUG) {
|
||||||
Log.i(TAG, "FrameTracker: CUJ=" + mSession.getName()
|
Log.i(TAG, "finish: CUJ=" + mSession.getName()
|
||||||
+ " (" + mBeginVsyncId + "," + mEndVsyncId + ")"
|
+ " (" + mBeginVsyncId + "," + mEndVsyncId + ")"
|
||||||
+ " totalFrames=" + totalFramesCount
|
+ " totalFrames=" + totalFramesCount
|
||||||
+ " missedAppFrames=" + missedAppFramesCount
|
+ " missedAppFrames=" + missedAppFramesCount
|
||||||
|
|||||||
Reference in New Issue
Block a user