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
This commit is contained in:
Jorim Jaggi
2021-04-23 14:58:06 +02:00
parent 1abb5dc24e
commit e941d4e58b
2 changed files with 17 additions and 2 deletions

View File

@@ -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());
Trace.beginAsyncSection(mSession.getName(), (int) mBeginVsyncId);
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;

View File

@@ -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 {