Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4bcbffd5 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Add presentTime to FrameInfo

Present time is available to apps, but is not currently stored inside
FrameInfo. In this CL, we add a location for storing the present time inside
FrameInfo.

Currently, the metrics reporter is triggered after the buffer is sent to
SurfaceFlinger. That means, metrics for anything that happens after gpu
draw completes are currently not available.

In a future CL, we will populate the 'presentTime' field.

In a future CL, we will register a metrics observer inside ViewRootImpl
in order to send this data to InputDispatcher. This will enable
end-to-end touch latency metrics collection.

Bug: 169866723
Test: printed present time inside FrameTimeline.cpp (surfaceflinger
side) and compared to the values printed inside a metrics observer
registered in ViewRootImpl (not done in this CL)
Test: atest ViewFrameInfoTest

Change-Id: I7d0f8c5d7b5a2572abdc4e107123e8938a36f582
parent be7698d6
Loading
Loading
Loading
Loading
+21 −17
Original line number Diff line number Diff line
@@ -213,8 +213,7 @@ public final class FrameMetrics {
            Index.FRAME_TIMELINE_VSYNC_ID,
            Index.INTENDED_VSYNC,
            Index.VSYNC,
            Index.OLDEST_INPUT_EVENT,
            Index.NEWEST_INPUT_EVENT,
            Index.INPUT_EVENT_ID,
            Index.HANDLE_INPUT_START,
            Index.ANIMATION_START,
            Index.PERFORM_TRAVERSALS_START,
@@ -225,8 +224,11 @@ public final class FrameMetrics {
            Index.ISSUE_DRAW_COMMANDS_START,
            Index.SWAP_BUFFERS,
            Index.FRAME_COMPLETED,
            Index.DEQUEUE_BUFFER_DURATION,
            Index.QUEUE_BUFFER_DURATION,
            Index.GPU_COMPLETED,
            Index.SWAP_BUFFERS_COMPLETED
            Index.SWAP_BUFFERS_COMPLETED,
            Index.DISPLAY_PRESENT_TIME,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Index {
@@ -234,20 +236,22 @@ public final class FrameMetrics {
        int FRAME_TIMELINE_VSYNC_ID = 1;
        int INTENDED_VSYNC = 2;
        int VSYNC = 3;
        int OLDEST_INPUT_EVENT = 4;
        int NEWEST_INPUT_EVENT = 5;
        int HANDLE_INPUT_START = 6;
        int ANIMATION_START = 7;
        int PERFORM_TRAVERSALS_START = 8;
        int DRAW_START = 9;
        int FRAME_DEADLINE = 10;
        int SYNC_QUEUED = 11;
        int SYNC_START = 12;
        int ISSUE_DRAW_COMMANDS_START = 13;
        int SWAP_BUFFERS = 14;
        int FRAME_COMPLETED = 15;
        int GPU_COMPLETED = 18;
        int SWAP_BUFFERS_COMPLETED = 19;
        int INPUT_EVENT_ID = 4;
        int HANDLE_INPUT_START = 5;
        int ANIMATION_START = 6;
        int PERFORM_TRAVERSALS_START = 7;
        int DRAW_START = 8;
        int FRAME_DEADLINE = 9;
        int SYNC_QUEUED = 10;
        int SYNC_START = 11;
        int ISSUE_DRAW_COMMANDS_START = 12;
        int SWAP_BUFFERS = 13;
        int FRAME_COMPLETED = 14;
        int DEQUEUE_BUFFER_DURATION = 15;
        int QUEUE_BUFFER_DURATION = 16;
        int GPU_COMPLETED = 17;
        int SWAP_BUFFERS_COMPLETED = 18;
        int DISPLAY_PRESENT_TIME = 19;

        int FRAME_STATS_COUNT = 20; // must always be last and in sync with
                                    // FrameInfoIndex::NumIndexes in libs/hwui/FrameInfo.h
+2 −2
Original line number Diff line number Diff line
@@ -58,8 +58,8 @@ public class ViewFrameInfo {
    public void populateFrameInfo(FrameInfo frameInfo) {
        frameInfo.frameInfo[FrameInfo.FLAGS] |= flags;
        frameInfo.frameInfo[FrameInfo.DRAW_START] = drawStart;
        frameInfo.frameInfo[FrameInfo.OLDEST_INPUT_EVENT] = oldestInputEventTime;
        frameInfo.frameInfo[FrameInfo.NEWEST_INPUT_EVENT] = newestInputEventTime;
        // TODO(b/169866723): Use InputEventAssigner
        frameInfo.frameInfo[FrameInfo.INPUT_EVENT_ID] = newestInputEventTime;
    }

    /**
+8 −10
Original line number Diff line number Diff line
@@ -69,28 +69,26 @@ public final class FrameInfo {
    // animation & drawing system
    public static final int VSYNC = 3;

    // The time of the oldest input event
    public static final int OLDEST_INPUT_EVENT = 4;

    // The time of the newest input event
    public static final int NEWEST_INPUT_EVENT = 5;
    // The id of the input event that caused the current frame
    public static final int INPUT_EVENT_ID = 4;

    // When input event handling started
    public static final int HANDLE_INPUT_START = 6;
    public static final int HANDLE_INPUT_START = 5;

    // When animation evaluations started
    public static final int ANIMATION_START = 7;
    public static final int ANIMATION_START = 6;

    // When ViewRootImpl#performTraversals() started
    public static final int PERFORM_TRAVERSALS_START = 8;
    public static final int PERFORM_TRAVERSALS_START = 7;

    // When View:draw() started
    public static final int DRAW_START = 9;
    public static final int DRAW_START = 8;

    // When the frame needs to be ready by
    public static final int FRAME_DEADLINE = 10;
    public static final int FRAME_DEADLINE = 9;

    // Must be the last one
    // This value must be in sync with `UI_THREAD_FRAME_INFO_SIZE` in FrameInfo.h
    private static final int FRAME_INFO_SIZE = FRAME_DEADLINE + 1;

    /** checkstyle */
+4 −4
Original line number Diff line number Diff line
@@ -20,13 +20,12 @@
namespace android {
namespace uirenderer {

const std::array<std::string, static_cast<int>(FrameInfoIndex::NumIndexes)> FrameInfoNames = {
const std::array FrameInfoNames{
        "Flags",
        "FrameTimelineVsyncId",
        "IntendedVsync",
        "Vsync",
        "OldestInputEvent",
        "NewestInputEvent",
        "InputEventId",
        "HandleInputStart",
        "AnimationStart",
        "PerformTraversalsStart",
@@ -40,7 +39,8 @@ const std::array<std::string, static_cast<int>(FrameInfoIndex::NumIndexes)> Fram
        "DequeueBufferDuration",
        "QueueBufferDuration",
        "GpuCompleted",
        "SwapBuffersCompleted"
        "SwapBuffersCompleted",
        "DisplayPresentTime",
};

static_assert(static_cast<int>(FrameInfoIndex::NumIndexes) == 20,
+4 −4
Original line number Diff line number Diff line
@@ -28,15 +28,14 @@
namespace android {
namespace uirenderer {

#define UI_THREAD_FRAME_INFO_SIZE 11
static constexpr size_t UI_THREAD_FRAME_INFO_SIZE = 10;

enum class FrameInfoIndex {
    Flags = 0,
    FrameTimelineVsyncId,
    IntendedVsync,
    Vsync,
    OldestInputEvent,
    NewestInputEvent,
    InputEventId,
    HandleInputStart,
    AnimationStart,
    PerformTraversalsStart,
@@ -56,13 +55,14 @@ enum class FrameInfoIndex {

    GpuCompleted,
    SwapBuffersCompleted,
    DisplayPresentTime,

    // Must be the last value!
    // Also must be kept in sync with FrameMetrics.java#FRAME_STATS_COUNT
    NumIndexes
};

extern const std::array<std::string, static_cast<int>(FrameInfoIndex::NumIndexes)> FrameInfoNames;
extern const std::array<const char*, static_cast<int>(FrameInfoIndex::NumIndexes)> FrameInfoNames;

namespace FrameInfoFlags {
enum {
Loading