Merge "Reduce memory churn from main thread looper tracing" into main

This commit is contained in:
Marcin Oczeretko
2023-07-20 12:49:25 +00:00
committed by Android (Google) Code Review
3 changed files with 44 additions and 26 deletions

View File

@@ -34,6 +34,7 @@ import android.os.Message;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.TraceNameSupplier;
import android.util.Log;
import android.util.TimeUtils;
import android.view.animation.AnimationUtils;
@@ -1319,7 +1320,7 @@ public final class Choreographer {
}
private final class FrameDisplayEventReceiver extends DisplayEventReceiver
implements Runnable {
implements Runnable, TraceNameSupplier {
private boolean mHavePendingVsync;
private long mTimestampNanos;
private int mFrame;
@@ -1377,6 +1378,14 @@ public final class Choreographer {
mHavePendingVsync = false;
doFrame(mTimestampNanos, mFrame, mLastVsyncEventData);
}
@androidx.annotation.NonNull
@Override
public String getTraceName() {
// Returning just a simple name.
// More detailed logging happens in onVsync() for TRACE_TAG_VIEW.
return "FrameDisplayEventReceiver";
}
}
private static final class CallbackRecord {

View File

@@ -5795,6 +5795,15 @@ public final class ViewRootImpl implements ViewParent,
private static final int MSG_PAUSED_FOR_SYNC_TIMEOUT = 37;
final class ViewRootHandler extends Handler {
@androidx.annotation.NonNull
@Override
public String getTraceName(@androidx.annotation.NonNull Message message) {
if (message.getCallback() == null) {
return getMessageName(message);
}
return super.getTraceName(message);
}
@Override
public String getMessageName(Message message) {
switch (message.what) {

View File

@@ -502,35 +502,35 @@ public class FrameTracker extends SurfaceControl.OnJankDataListener
return vsyncId >= mBeginVsyncId;
}
// This will be executed in the HardwareRendererObserver handler, which is the FrameTracker
// handler by construction.
@Override
public void onFrameMetricsAvailable(int dropCountSinceLastInvocation) {
postCallback(() -> {
if (mCancelled || mMetricsFinalized) {
return;
}
if (mCancelled || mMetricsFinalized) {
return;
}
// Since this callback might come a little bit late after the end() call.
// We should keep tracking the begin / end timestamp that we can compare with
// vsync timestamp to check if the frame is in the duration of the CUJ.
long totalDurationNanos = mMetricsWrapper.getMetric(FrameMetrics.TOTAL_DURATION);
boolean isFirstFrame = mMetricsWrapper.getMetric(FrameMetrics.FIRST_DRAW_FRAME) == 1;
long frameVsyncId =
mMetricsWrapper.getTiming()[FrameMetrics.Index.FRAME_TIMELINE_VSYNC_ID];
// Since this callback might come a little bit late after the end() call.
// We should keep tracking the begin / end timestamp that we can compare with
// vsync timestamp to check if the frame is in the duration of the CUJ.
long totalDurationNanos = mMetricsWrapper.getMetric(FrameMetrics.TOTAL_DURATION);
boolean isFirstFrame = mMetricsWrapper.getMetric(FrameMetrics.FIRST_DRAW_FRAME) == 1;
long frameVsyncId =
mMetricsWrapper.getTiming()[FrameMetrics.Index.FRAME_TIMELINE_VSYNC_ID];
if (!isInRange(frameVsyncId)) {
return;
}
JankInfo info = findJankInfo(frameVsyncId);
if (info != null) {
info.hwuiCallbackFired = true;
info.totalDurationNanos = totalDurationNanos;
info.isFirstFrame = isFirstFrame;
} else {
mJankInfos.put((int) frameVsyncId, JankInfo.createFromHwuiCallback(
frameVsyncId, totalDurationNanos, isFirstFrame));
}
processJankInfos();
});
if (!isInRange(frameVsyncId)) {
return;
}
JankInfo info = findJankInfo(frameVsyncId);
if (info != null) {
info.hwuiCallbackFired = true;
info.totalDurationNanos = totalDurationNanos;
info.isFirstFrame = isFirstFrame;
} else {
mJankInfos.put((int) frameVsyncId, JankInfo.createFromHwuiCallback(
frameVsyncId, totalDurationNanos, isFirstFrame));
}
processJankInfos();
}
@UiThread