Recompute the mNextFrameStartUnstuffed on every frame
At runtime, the intended_vsync difference is not constant value of
16.66ms. If JankTracker repeatedly adds 16.66ms to
mNextFrameStartUnstuffed, it might be difted away after the tiny
differences being accumulated over many frames.
This Cl re-computes mNextFrameStartUnstuffed based on intended_vsync
for each triple buffering frame.
Test: existing JankTrackerTests
Change-Id: Ifa0b456be61905648f87327bddc3328e9abfef0a
diff --git a/libs/hwui/JankTracker.cpp b/libs/hwui/JankTracker.cpp
index 4b0ddd2..c5c2d15 100644
--- a/libs/hwui/JankTracker.cpp
+++ b/libs/hwui/JankTracker.cpp
@@ -206,6 +206,7 @@
frame.set(FrameInfoIndex::FrameDeadline) = deadline;
}
+ bool computeNextFrameStartUnstuffed = false;
// If we hit the deadline, cool!
if (frame[FrameInfoIndex::GpuCompleted] < deadline) {
if (isTripleBuffered) {
@@ -213,7 +214,8 @@
(*mGlobalData)->reportJankType(JankType::kHighInputLatency);
// Buffer stuffing state gets carried over to next frame, unless there is a "pause"
- mNextFrameStartUnstuffed += frameInterval;
+ // Instead of increase by frameInterval, recompute to catch up the drifting vsync
+ computeNextFrameStartUnstuffed = true;
}
} else {
mData->reportJankType(JankType::kMissedDeadline);
@@ -222,14 +224,7 @@
(*mGlobalData)->reportJank();
// Janked, store the adjust deadline to detect triple buffering in next frame correctly.
- nsecs_t jitterNanos = frame[FrameInfoIndex::GpuCompleted]
- - frame[FrameInfoIndex::Vsync];
- nsecs_t lastFrameOffset = jitterNanos % frameInterval;
-
- // Note the time when the next frame would start in an unstuffed situation. If it starts
- // earlier, we are in a stuffed situation.
- mNextFrameStartUnstuffed = frame[FrameInfoIndex::GpuCompleted]
- - lastFrameOffset + frameInterval;
+ computeNextFrameStartUnstuffed = true;
recomputeThresholds(frameInterval);
for (auto& comparison : COMPARISONS) {
@@ -254,6 +249,16 @@
}
}
+ if (computeNextFrameStartUnstuffed) {
+ nsecs_t jitterNanos = frame[FrameInfoIndex::GpuCompleted] - frame[FrameInfoIndex::Vsync];
+ nsecs_t lastFrameOffset = jitterNanos % frameInterval;
+
+ // Note the time when the next frame would start in an unstuffed situation. If it starts
+ // earlier, we are in a stuffed situation.
+ mNextFrameStartUnstuffed =
+ frame[FrameInfoIndex::GpuCompleted] - lastFrameOffset + frameInterval;
+ }
+
int64_t totalGPUDrawTime = frame.gpuDrawTime();
if (totalGPUDrawTime >= 0) {
mData->reportGPUFrame(totalGPUDrawTime);