From adf5024a5d6fa89a9214af195acbafb8da1df2d4 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 11 Mar 2021 21:21:05 +0000 Subject: [PATCH] Send metrics notification just before frame advances Currently, it is possible to notify frame metrics observers that registered to receive present time about the same frame twice. This is wasteful, but also requires the metrics listener to guard against duplicates. See https://b.corp.google.com/issues/169866723#comment23 To avoid this issue, only notify about metrics with present time just before the frame is advanced to the next position. This ensures that we are always notifying about the last frame that's about to go away. Bug: 169866723 Test: added a crash to LatencyTracker for the case where we are notified about non-existent record. The record disappears once it's complete. So the first call was completing the record, and the second call was causing a crash. Now, the crash is gone with this patch. Change-Id: Ia247b4a0010b8ecb016ac66e44e211ec4f40bf8f --- libs/hwui/renderthread/CanvasContext.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index 9793300b406de..800c58095041b 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -576,6 +576,7 @@ void CanvasContext::draw() { if (requireSwap) { if (mExpectSurfaceStats) { + reportMetricsWithPresentTime(); std::lock_guard lock(mLast4FrameInfosMutex); std::pair& next = mLast4FrameInfos.next(); next.first = mCurrentFrameInfo; @@ -656,8 +657,6 @@ void CanvasContext::onSurfaceStatsAvailable(void* context, ASurfaceControl* cont } } - instance->reportMetricsWithPresentTime(); - if (frameInfo != nullptr) { if (gpuCompleteTime == -1) { gpuCompleteTime = frameInfo->get(FrameInfoIndex::SwapBuffersCompleted);