Pass latency information from app to input
Once the app learns about the frame's timeline, it will tell
inputdispatcher about it. We are adding a new callback similar to
'finishInputEvent', called 'reportLatencyInfo'.
This will tell inputdispatcher about the queue time and the present time
of each frame that was caused by input.
InputDispatcher will then be able to reconstruct the input event
timeline and report the end-to-end latency metrics.
In a separate CL, we will add LatencyTracker, which will eventually
receive this data.
Using the event id and the provided queue time and present time, we will
be able to reconstruct the end-to-end latency inside LatencyTracker.
Bug: 167947340
Test: atest inputflinger_tests libinput_tests
Change-Id: I181532a01b34eecd186bc3c74db289fc59c5955c
diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp
index fc31715..088e00b 100644
--- a/libs/input/tests/InputPublisherAndConsumer_test.cpp
+++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp
@@ -124,13 +124,15 @@
ASSERT_EQ(OK, status)
<< "consumer sendFinishedSignal should return OK";
- Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal();
- ASSERT_TRUE(result.ok()) << "publisher receiveFinishedSignal should return OK";
- ASSERT_EQ(seq, result->seq)
- << "receiveFinishedSignal should have returned the original sequence number";
- ASSERT_TRUE(result->handled)
- << "receiveFinishedSignal should have set handled to consumer's reply";
- ASSERT_GE(result->consumeTime, publishTime)
+ Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
+ ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
+ ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
+ const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
+ ASSERT_EQ(seq, finish.seq)
+ << "receiveConsumerResponse should have returned the original sequence number";
+ ASSERT_TRUE(finish.handled)
+ << "receiveConsumerResponse should have set handled to consumer's reply";
+ ASSERT_GE(finish.consumeTime, publishTime)
<< "finished signal's consume time should be greater than publish time";
}
@@ -264,13 +266,15 @@
ASSERT_EQ(OK, status)
<< "consumer sendFinishedSignal should return OK";
- Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal();
- ASSERT_TRUE(result.ok()) << "receiveFinishedSignal should return OK";
- ASSERT_EQ(seq, result->seq)
- << "receiveFinishedSignal should have returned the original sequence number";
- ASSERT_FALSE(result->handled)
- << "receiveFinishedSignal should have set handled to consumer's reply";
- ASSERT_GE(result->consumeTime, publishTime)
+ Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
+ ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
+ ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
+ const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
+ ASSERT_EQ(seq, finish.seq)
+ << "receiveConsumerResponse should have returned the original sequence number";
+ ASSERT_FALSE(finish.handled)
+ << "receiveConsumerResponse should have set handled to consumer's reply";
+ ASSERT_GE(finish.consumeTime, publishTime)
<< "finished signal's consume time should be greater than publish time";
}
@@ -304,14 +308,16 @@
status = mConsumer->sendFinishedSignal(seq, true);
ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
- Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal();
+ Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
+ ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
+ ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
+ const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
- ASSERT_TRUE(result.ok()) << "receiveFinishedSignal should return OK";
- ASSERT_EQ(seq, result->seq)
- << "receiveFinishedSignal should have returned the original sequence number";
- ASSERT_TRUE(result->handled)
- << "receiveFinishedSignal should have set handled to consumer's reply";
- ASSERT_GE(result->consumeTime, publishTime)
+ ASSERT_EQ(seq, finish.seq)
+ << "receiveConsumerResponse should have returned the original sequence number";
+ ASSERT_TRUE(finish.handled)
+ << "receiveConsumerResponse should have set handled to consumer's reply";
+ ASSERT_GE(finish.consumeTime, publishTime)
<< "finished signal's consume time should be greater than publish time";
}
@@ -343,13 +349,15 @@
status = mConsumer->sendFinishedSignal(seq, true);
ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
- android::base::Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal();
- ASSERT_TRUE(result.ok()) << "publisher receiveFinishedSignal should return OK";
- ASSERT_EQ(seq, result->seq)
- << "receiveFinishedSignal should have returned the original sequence number";
- ASSERT_TRUE(result->handled)
- << "receiveFinishedSignal should have set handled to consumer's reply";
- ASSERT_GE(result->consumeTime, publishTime)
+ Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
+ ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
+ ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
+ const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
+ ASSERT_EQ(seq, finish.seq)
+ << "receiveConsumerResponse should have returned the original sequence number";
+ ASSERT_TRUE(finish.handled)
+ << "receiveConsumerResponse should have set handled to consumer's reply";
+ ASSERT_GE(finish.consumeTime, publishTime)
<< "finished signal's consume time should be greater than publish time";
}
@@ -385,16 +393,34 @@
status = mConsumer->sendFinishedSignal(seq, true);
ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
- android::base::Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal();
- ASSERT_TRUE(result.ok()) << "publisher receiveFinishedSignal should return OK";
- ASSERT_EQ(seq, result->seq)
- << "publisher receiveFinishedSignal should have returned the original sequence number";
- ASSERT_TRUE(result->handled)
- << "publisher receiveFinishedSignal should have set handled to consumer's reply";
- ASSERT_GE(result->consumeTime, publishTime)
+ Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
+ ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
+ ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
+ const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
+ ASSERT_EQ(seq, finish.seq)
+ << "receiveConsumerResponse should have returned the original sequence number";
+ ASSERT_TRUE(finish.handled)
+ << "receiveConsumerResponse should have set handled to consumer's reply";
+ ASSERT_GE(finish.consumeTime, publishTime)
<< "finished signal's consume time should be greater than publish time";
}
+TEST_F(InputPublisherAndConsumerTest, SendTimeline) {
+ const int32_t inputEventId = 20;
+ std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline;
+ graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 30;
+ graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 40;
+ status_t status = mConsumer->sendTimeline(inputEventId, graphicsTimeline);
+ ASSERT_EQ(OK, status);
+
+ Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
+ ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
+ ASSERT_TRUE(std::holds_alternative<InputPublisher::Timeline>(*result));
+ const InputPublisher::Timeline& timeline = std::get<InputPublisher::Timeline>(*result);
+ ASSERT_EQ(inputEventId, timeline.inputEventId);
+ ASSERT_EQ(graphicsTimeline, timeline.graphicsTimeline);
+}
+
TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
}