Pass ProductId+VendorId+Source info to LatencyTracker
Currently InputEventLatencySketch captures the aggregated latency over
all devices, and it doesn't capture per-device latency.
In order to capture latency metrics per device, we track the timeline
for latency information for each Product Id, Vendor Id and Source
individually.
Bug: 270049345
Test: atest inputflinger_tests:LatencyTrackerTest
Change-Id: Ic3265e25ff95266e8cfe8542d4f4afb7b6ac16b1
diff --git a/services/inputflinger/dispatcher/LatencyTracker.cpp b/services/inputflinger/dispatcher/LatencyTracker.cpp
index b7c36a8..698bd9f 100644
--- a/services/inputflinger/dispatcher/LatencyTracker.cpp
+++ b/services/inputflinger/dispatcher/LatencyTracker.cpp
@@ -16,6 +16,7 @@
#define LOG_TAG "LatencyTracker"
#include "LatencyTracker.h"
+#include "../InputDeviceMetricsSource.h"
#include <inttypes.h>
@@ -23,6 +24,7 @@
#include <android-base/stringprintf.h>
#include <android/os/IInputConstants.h>
#include <input/Input.h>
+#include <input/InputDevice.h>
#include <log/log.h>
using android::base::HwTimeoutMultiplier;
@@ -66,7 +68,8 @@
}
void LatencyTracker::trackListener(int32_t inputEventId, bool isDown, nsecs_t eventTime,
- nsecs_t readTime) {
+ nsecs_t readTime, DeviceId deviceId,
+ const std::set<InputDeviceUsageSource>& sources) {
reportAndPruneMatureRecords(eventTime);
const auto it = mTimelines.find(inputEventId);
if (it != mTimelines.end()) {
@@ -78,7 +81,29 @@
eraseByValue(mEventTimes, inputEventId);
return;
}
- mTimelines.emplace(inputEventId, InputEventTimeline(isDown, eventTime, readTime));
+
+ // Create an InputEventTimeline for the device ID. The vendorId and productId
+ // can be obtained from the InputDeviceIdentifier of the particular device.
+ const InputDeviceIdentifier* identifier = nullptr;
+ for (auto& inputDevice : mInputDevices) {
+ if (deviceId == inputDevice.getId()) {
+ identifier = &inputDevice.getIdentifier();
+ break;
+ }
+ }
+
+ // If no matching ids can be found for the device from among the input devices connected,
+ // the call to trackListener will be dropped.
+ // Note: there generally isn't expected to be a situation where we can't find an InputDeviceInfo
+ // but a possibility of it is handled in case of race conditions
+ if (identifier == nullptr) {
+ ALOGE("Could not find input device identifier. Dropping call to LatencyTracker.");
+ return;
+ }
+
+ mTimelines.emplace(inputEventId,
+ InputEventTimeline(isDown, eventTime, readTime, identifier->vendor,
+ identifier->product, sources));
mEventTimes.emplace(eventTime, inputEventId);
}
@@ -171,4 +196,8 @@
StringPrintf("%s mEventTimes.size() = %zu\n", prefix, mEventTimes.size());
}
+void LatencyTracker::setInputDevices(const std::vector<InputDeviceInfo>& inputDevices) {
+ mInputDevices = inputDevices;
+}
+
} // namespace android::inputdispatcher