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
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 9793300..800c580 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -576,6 +576,7 @@
if (requireSwap) {
if (mExpectSurfaceStats) {
+ reportMetricsWithPresentTime();
std::lock_guard lock(mLast4FrameInfosMutex);
std::pair<FrameInfo*, int64_t>& next = mLast4FrameInfos.next();
next.first = mCurrentFrameInfo;
@@ -656,8 +657,6 @@
}
}
- instance->reportMetricsWithPresentTime();
-
if (frameInfo != nullptr) {
if (gpuCompleteTime == -1) {
gpuCompleteTime = frameInfo->get(FrameInfoIndex::SwapBuffersCompleted);