Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3aeff205 authored by Ioana Jianu's avatar Ioana Jianu Committed by Android (Google) Code Review
Browse files

Merge "Gather latency metrics for key events" into main

parents a2f940ee 099e19a9
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -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));
+20 −0
Original line number Diff line number Diff line
@@ -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,
+7 −0
Original line number Diff line number Diff line
@@ -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);