Cache flag value to prevent performance regressions
Cache the value of the enable_per_device_input_latency_metrics flag
to prevent performace regressions.
Bug: 369812450
Test: atest inputflinger_tests
Flag: com.android.input.flags.enable_per_device_input_latency_metrics
Change-Id: I7afc2eb5ce25ae4be12bcb836f8645f1168b9e94
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index b0beeca..182789d 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -1029,7 +1029,7 @@
const nsecs_t nextAnrCheck = processAnrsLocked();
nextWakeupTime = std::min(nextWakeupTime, nextAnrCheck);
- if (input_flags::enable_per_device_input_latency_metrics()) {
+ if (mPerDeviceInputLatencyMetricsFlag) {
const nsecs_t nextStatisticsPush = processLatencyStatisticsLocked();
nextWakeupTime = std::min(nextWakeupTime, nextStatisticsPush);
}
@@ -4548,7 +4548,7 @@
newEntry->traceTracker = mTracer->traceInboundEvent(*newEntry);
}
- if (input_flags::enable_per_device_input_latency_metrics()) {
+ if (mPerDeviceInputLatencyMetricsFlag) {
if (args.id != android::os::IInputConstants::INVALID_INPUT_EVENT_ID &&
IdGenerator::getSource(args.id) == IdGenerator::Source::INPUT_READER &&
!mInputFilterEnabled) {
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index d90b9de..24e36ae 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -16,6 +16,8 @@
#pragma once
+#include <com_android_input_flags.h>
+
#include "AnrTracker.h"
#include "CancelationOptions.h"
#include "DragState.h"
@@ -741,6 +743,10 @@
sp<android::gui::WindowInfoHandle> findWallpaperWindowBelow(
const sp<android::gui::WindowInfoHandle>& windowHandle) const REQUIRES(mLock);
+
+ /** Stores the value of the input flag for per device input latency metrics. */
+ const bool mPerDeviceInputLatencyMetricsFlag =
+ com::android::input::flags::enable_per_device_input_latency_metrics();
};
} // namespace android::inputdispatcher