From 3afb3972f458c299c92933d9856a542d837c1998 Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Fri, 27 May 2022 22:03:11 +0000 Subject: Make GPU duration metrics more accurate for Vulkan In the Vulkan pipeline, the GPU start time was measured to be when swapBuffers starts. But the command queue has already been submitted at this point, which means that the GPU work would already have begun. This means that it's possible to measure a negative time since for very light GPU workloads, the GPU fence can fire prior to CPU making it to swapBuffers(). To compensate, instead measure from after skia completed submitting GPU commands, until the GPU fence fires. Since it is theoretically possible for GPU work to complete if the render thread gets descheduled immediately after submitting the GPU, we also add some clamping to ensure that the duration from command submission -> completion of GPU work is nonnegative. Bug: 230713131 Test: atest android.view.cts.FrameMetricsListenerTest Change-Id: Ia30b7732eaab71e4e29766f788d5cd94ec63c38a --- libs/hwui/FrameInfo.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'libs/hwui/FrameInfo.cpp') diff --git a/libs/hwui/FrameInfo.cpp b/libs/hwui/FrameInfo.cpp index fecf26906c04..8191f5e6a83a 100644 --- a/libs/hwui/FrameInfo.cpp +++ b/libs/hwui/FrameInfo.cpp @@ -20,19 +20,33 @@ namespace android { namespace uirenderer { -const std::array FrameInfoNames{ - "Flags", "FrameTimelineVsyncId", "IntendedVsync", - "Vsync", "InputEventId", "HandleInputStart", - "AnimationStart", "PerformTraversalsStart", "DrawStart", - "FrameDeadline", "FrameInterval", "FrameStartTime", - "SyncQueued", "SyncStart", "IssueDrawCommandsStart", - "SwapBuffers", "FrameCompleted", "DequeueBufferDuration", - "QueueBufferDuration", "GpuCompleted", "SwapBuffersCompleted", - "DisplayPresentTime", +const std::array FrameInfoNames{"Flags", + "FrameTimelineVsyncId", + "IntendedVsync", + "Vsync", + "InputEventId", + "HandleInputStart", + "AnimationStart", + "PerformTraversalsStart", + "DrawStart", + "FrameDeadline", + "FrameInterval", + "FrameStartTime", + "SyncQueued", + "SyncStart", + "IssueDrawCommandsStart", + "SwapBuffers", + "FrameCompleted", + "DequeueBufferDuration", + "QueueBufferDuration", + "GpuCompleted", + "SwapBuffersCompleted", + "DisplayPresentTime", + "CommandSubmissionCompleted" }; -static_assert(static_cast(FrameInfoIndex::NumIndexes) == 22, +static_assert(static_cast(FrameInfoIndex::NumIndexes) == 23, "Must update value in FrameMetrics.java#FRAME_STATS_COUNT (and here)"); void FrameInfo::importUiThreadInfo(int64_t* info) { -- cgit v1.2.3-59-g8ed1b