summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ioana Jianu <jioana@google.com> 2024-09-25 10:19:41 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-09-25 10:19:41 +0000
commit3aeff205e1917b2646dc0b7a86c0fe6a2e37826f (patch)
tree56d1bd57c3990291e234d096e2fb1ccd0f63ab56
parenta2f940eece32ba5e305a5309d4cc00677951bd63 (diff)
parent099e19a97f2eac446d0cbd1c61ad3cf4e18c4a65 (diff)
Merge "Gather latency metrics for key events" into main
-rw-r--r--services/inputflinger/dispatcher/InputDispatcher.cpp12
-rw-r--r--services/inputflinger/dispatcher/LatencyTracker.cpp20
-rw-r--r--services/inputflinger/dispatcher/LatencyTracker.h7
3 files changed, 36 insertions, 3 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 9cf9487be0..b0beeca43c 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -4548,6 +4548,14 @@ void InputDispatcher::notifyKey(const NotifyKeyArgs& args) {
newEntry->traceTracker = mTracer->traceInboundEvent(*newEntry);
}
+ if (input_flags::enable_per_device_input_latency_metrics()) {
+ if (args.id != android::os::IInputConstants::INVALID_INPUT_EVENT_ID &&
+ IdGenerator::getSource(args.id) == IdGenerator::Source::INPUT_READER &&
+ !mInputFilterEnabled) {
+ mLatencyTracker.trackNotifyKey(args);
+ }
+ }
+
needWake = enqueueInboundEventLocked(std::move(newEntry));
mLock.unlock();
} // release lock
@@ -4680,9 +4688,7 @@ void InputDispatcher::notifyMotion(const NotifyMotionArgs& args) {
if (args.id != android::os::IInputConstants::INVALID_INPUT_EVENT_ID &&
IdGenerator::getSource(args.id) == IdGenerator::Source::INPUT_READER &&
!mInputFilterEnabled) {
- std::set<InputDeviceUsageSource> sources = getUsageSourcesForMotionArgs(args);
- mLatencyTracker.trackListener(args.id, args.eventTime, args.readTime, args.deviceId,
- sources, args.action, InputEventType::MOTION);
+ mLatencyTracker.trackNotifyMotion(args);
}
needWake = enqueueInboundEventLocked(std::move(newEntry));
diff --git a/services/inputflinger/dispatcher/LatencyTracker.cpp b/services/inputflinger/dispatcher/LatencyTracker.cpp
index d203fbabf6..0852026823 100644
--- a/services/inputflinger/dispatcher/LatencyTracker.cpp
+++ b/services/inputflinger/dispatcher/LatencyTracker.cpp
@@ -65,6 +65,26 @@ static void eraseByValue(std::multimap<K, V>& map, const V& value) {
LatencyTracker::LatencyTracker(InputEventTimelineProcessor& processor)
: mTimelineProcessor(&processor) {}
+void LatencyTracker::trackNotifyMotion(const NotifyMotionArgs& args) {
+ std::set<InputDeviceUsageSource> sources = getUsageSourcesForMotionArgs(args);
+ trackListener(args.id, args.eventTime, args.readTime, args.deviceId, sources, args.action,
+ InputEventType::MOTION);
+}
+
+void LatencyTracker::trackNotifyKey(const NotifyKeyArgs& args) {
+ int32_t keyboardType = AINPUT_KEYBOARD_TYPE_NONE;
+ for (auto& inputDevice : mInputDevices) {
+ if (args.deviceId == inputDevice.getId()) {
+ keyboardType = inputDevice.getKeyboardType();
+ break;
+ }
+ }
+ std::set<InputDeviceUsageSource> sources =
+ std::set{getUsageSourceForKeyArgs(keyboardType, args)};
+ trackListener(args.id, args.eventTime, args.readTime, args.deviceId, sources, args.action,
+ InputEventType::KEY);
+}
+
void LatencyTracker::trackListener(int32_t inputEventId, nsecs_t eventTime, nsecs_t readTime,
DeviceId deviceId,
const std::set<InputDeviceUsageSource>& sources,
diff --git a/services/inputflinger/dispatcher/LatencyTracker.h b/services/inputflinger/dispatcher/LatencyTracker.h
index 80d3f2f294..eb58222ce6 100644
--- a/services/inputflinger/dispatcher/LatencyTracker.h
+++ b/services/inputflinger/dispatcher/LatencyTracker.h
@@ -59,6 +59,13 @@ public:
nsecs_t deliveryTime, nsecs_t consumeTime, nsecs_t finishTime);
void trackGraphicsLatency(int32_t inputEventId, const sp<IBinder>& connectionToken,
std::array<nsecs_t, GraphicsTimeline::SIZE> timeline);
+ /**
+ * trackNotifyMotion and trackNotifyKeys are intermediates between InputDispatcher and
+ * trackListener. They compute the InputDeviceUsageSource set and call trackListener with
+ * the relevant parameters for latency computation.
+ */
+ void trackNotifyMotion(const NotifyMotionArgs& args);
+ void trackNotifyKey(const NotifyKeyArgs& args);
std::string dump(const char* prefix) const;
void setInputDevices(const std::vector<InputDeviceInfo>& inputDevices);