Move LatencyStatistics collection from InputReader to InputTransport
This move allows us to grab a bigger context of how much time a motion
event is spent from the kernel to right before the event was published.
Test: Modified LatencyStats to report ever 10 seconds. Utilized logs to
check that logs were reporting every 10 seconds. Checked also using
logs that data was being added and calculated correctly.
Change-Id: Iee0f9a2155e93ae77de5a5cd8b9fd1506186c60f
Signed-off-by: Atif Niyaz <atifniyaz@google.com>
diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h
index df23f61..690e0a1 100644
--- a/include/input/InputTransport.h
+++ b/include/input/InputTransport.h
@@ -31,13 +31,16 @@
#include <string>
+#include <android-base/chrono_utils.h>
+
#include <binder/IBinder.h>
#include <input/Input.h>
-#include <utils/Errors.h>
-#include <utils/Timers.h>
-#include <utils/RefBase.h>
-#include <utils/Vector.h>
+#include <input/LatencyStatistics.h>
#include <utils/BitSet.h>
+#include <utils/Errors.h>
+#include <utils/RefBase.h>
+#include <utils/Timers.h>
+#include <utils/Vector.h>
namespace android {
class Parcel;
@@ -286,7 +289,12 @@
status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled);
private:
+ static constexpr std::chrono::duration TOUCH_STATS_REPORT_PERIOD = 5min;
+
sp<InputChannel> mChannel;
+ LatencyStatistics mTouchStatistics{TOUCH_STATS_REPORT_PERIOD};
+
+ void reportTouchEventForStatistics(nsecs_t evdevTime);
};
/*
diff --git a/libs/input/Android.bp b/libs/input/Android.bp
index 1713850..7749e66 100644
--- a/libs/input/Android.bp
+++ b/libs/input/Android.bp
@@ -56,7 +56,8 @@
shared_libs: [
"libutils",
"libbinder",
- "libui"
+ "libui",
+ "libstatslog",
],
sanitize: {
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index 904a6fe..2ff301e 100644
--- a/libs/input/InputTransport.cpp
+++ b/libs/input/InputTransport.cpp
@@ -34,6 +34,7 @@
#include <utils/Trace.h>
#include <input/InputTransport.h>
+#include <statslog.h>
using android::base::StringPrintf;
@@ -531,6 +532,10 @@
msg.body.motion.pointers[i].properties.copyFrom(pointerProperties[i]);
msg.body.motion.pointers[i].coords.copyFrom(pointerCoords[i]);
}
+
+ if (source == AINPUT_SOURCE_TOUCHSCREEN) {
+ reportTouchEventForStatistics(eventTime);
+ }
return mChannel->sendMessage(&msg);
}
@@ -557,6 +562,17 @@
return OK;
}
+void InputPublisher::reportTouchEventForStatistics(nsecs_t evdevTime) {
+ if (mTouchStatistics.shouldReport()) {
+ android::util::stats_write(android::util::TOUCH_EVENT_REPORTED, mTouchStatistics.getMin(),
+ mTouchStatistics.getMax(), mTouchStatistics.getMean(),
+ mTouchStatistics.getStDev(), mTouchStatistics.getCount());
+ mTouchStatistics.reset();
+ }
+ nsecs_t latency = nanoseconds_to_microseconds(systemTime(CLOCK_MONOTONIC) - evdevTime);
+ mTouchStatistics.addValue(latency);
+}
+
// --- InputConsumer ---
InputConsumer::InputConsumer(const sp<InputChannel>& channel) :
diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp
index 8dd4d1d..bdee6fe 100644
--- a/services/inputflinger/Android.bp
+++ b/services/inputflinger/Android.bp
@@ -88,7 +88,6 @@
"libui",
"libutils",
"libhardware_legacy",
- "libstatslog",
],
header_libs: [
diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp
index df5dcaf..d565e3a 100644
--- a/services/inputflinger/InputReader.cpp
+++ b/services/inputflinger/InputReader.cpp
@@ -57,7 +57,6 @@
#include <android-base/stringprintf.h>
#include <input/Keyboard.h>
#include <input/VirtualKeyMap.h>
-#include <statslog.h>
#define INDENT " "
#define INDENT2 " "
@@ -4310,24 +4309,12 @@
mExternalStylusFusionTimeout = LLONG_MAX;
}
-void TouchInputMapper::reportEventForStatistics(nsecs_t evdevTime) {
- if (mStatistics.shouldReport()) {
- android::util::stats_write(android::util::TOUCH_EVENT_REPORTED, mStatistics.getMin(),
- mStatistics.getMax(), mStatistics.getMean(),
- mStatistics.getStDev(), mStatistics.getCount());
- mStatistics.reset();
- }
- nsecs_t latency = nanoseconds_to_microseconds(systemTime(CLOCK_MONOTONIC) - evdevTime);
- mStatistics.addValue(latency);
-}
-
void TouchInputMapper::process(const RawEvent* rawEvent) {
mCursorButtonAccumulator.process(rawEvent);
mCursorScrollAccumulator.process(rawEvent);
mTouchButtonAccumulator.process(rawEvent);
if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
- reportEventForStatistics(rawEvent->when);
sync(rawEvent->when);
}
}
diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/InputReader.h
index 33763b6..e434869 100644
--- a/services/inputflinger/InputReader.h
+++ b/services/inputflinger/InputReader.h
@@ -24,7 +24,6 @@
#include <input/DisplayViewport.h>
#include <input/Input.h>
-#include <input/LatencyStatistics.h>
#include <input/VelocityControl.h>
#include <input/VelocityTracker.h>
#include <ui/DisplayInfo.h>
@@ -1509,11 +1508,6 @@
VelocityControl mWheelXVelocityControl;
VelocityControl mWheelYVelocityControl;
- static constexpr std::chrono::duration STATS_REPORT_PERIOD = 5min;
-
- // Latency statistics for touch events
- LatencyStatistics mStatistics{STATS_REPORT_PERIOD};
-
std::optional<DisplayViewport> findViewport();
void resetExternalStylus();
@@ -1582,8 +1576,6 @@
static void assignPointerIds(const RawState* last, RawState* current);
- void reportEventForStatistics(nsecs_t evdevTime);
-
const char* modeToString(DeviceMode deviceMode);
};