Merge "Mark instrument events of FrameTracker in the trace" into tm-dev

This commit is contained in:
Wu Ahan
2022-03-17 02:00:24 +00:00
committed by Android (Google) Code Review

View File

@@ -33,6 +33,7 @@ import android.annotation.Nullable;
import android.graphics.HardwareRendererObserver; import android.graphics.HardwareRendererObserver;
import android.os.Handler; import android.os.Handler;
import android.os.Trace; import android.os.Trace;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.Choreographer; import android.view.Choreographer;
@@ -188,6 +189,7 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
if (mBeginVsyncId != INVALID_ID) { if (mBeginVsyncId != INVALID_ID) {
mSurfaceControlWrapper.addJankStatsListener( mSurfaceControlWrapper.addJankStatsListener(
FrameTracker.this, mSurfaceControl); FrameTracker.this, mSurfaceControl);
markEvent("FT#deferMonitoring");
postTraceStartMarker(); postTraceStartMarker();
} }
} }
@@ -241,8 +243,9 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
} }
if (mSurfaceControl != null) { if (mSurfaceControl != null) {
if (mDeferMonitoring) { if (mDeferMonitoring) {
markEvent("FT#deferMonitoring");
// Normal case, we begin the instrument from the very beginning, // Normal case, we begin the instrument from the very beginning,
// except the first frame. // will exclude the first frame.
postTraceStartMarker(); postTraceStartMarker();
} else { } else {
// If we don't begin the instrument from the very beginning, // If we don't begin the instrument from the very beginning,
@@ -272,6 +275,7 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
return; return;
} }
mTracingStarted = true; mTracingStarted = true;
markEvent("FT#begin");
Trace.beginAsyncSection(mSession.getName(), (int) mBeginVsyncId); Trace.beginAsyncSection(mSession.getName(), (int) mBeginVsyncId);
} }
} }
@@ -295,6 +299,7 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
Log.d(TAG, "end: " + mSession.getName() Log.d(TAG, "end: " + mSession.getName()
+ ", end=" + mEndVsyncId + ", reason=" + reason); + ", end=" + mEndVsyncId + ", reason=" + reason);
} }
markEvent("FT#end#" + reason);
Trace.endAsyncSection(mSession.getName(), (int) mBeginVsyncId); Trace.endAsyncSection(mSession.getName(), (int) mBeginVsyncId);
mSession.setReason(reason); mSession.setReason(reason);
@@ -322,6 +327,7 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
reason == REASON_CANCEL_NOT_BEGUN || reason == REASON_CANCEL_SAME_VSYNC; reason == REASON_CANCEL_NOT_BEGUN || reason == REASON_CANCEL_SAME_VSYNC;
if (mCancelled || (mEndVsyncId != INVALID_ID && !cancelFromEnd)) return false; if (mCancelled || (mEndVsyncId != INVALID_ID && !cancelFromEnd)) return false;
mCancelled = true; mCancelled = true;
markEvent("FT#cancel#" + reason);
// We don't need to end the trace section if it never begun. // We don't need to end the trace section if it never begun.
if (mTracingStarted) { if (mTracingStarted) {
Trace.endAsyncSection(mSession.getName(), (int) mBeginVsyncId); Trace.endAsyncSection(mSession.getName(), (int) mBeginVsyncId);
@@ -343,6 +349,11 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
} }
} }
private void markEvent(String desc) {
Trace.beginSection(TextUtils.formatSimple("%s#%s", mSession.getName(), desc));
Trace.endSection();
}
private void notifyCujEvent(String action) { private void notifyCujEvent(String action) {
if (mListener == null) return; if (mListener == null) return;
mListener.onCujEvents(mSession, action); mListener.onCujEvents(mSession, action);