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

Commit cde5086b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I65538cd3,I4da2cff3,Ibee1e7dc into main

* changes:
  Remove tracing for InputDispatcher::enqueueDispatchEntryLocked
  Trace all InputListener stages
  Improve existing InputDispatcher traces
parents e3ce97ea 6d1cb012
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <utils/Trace.h>
#include <optional>

#define ATRACE_NAME_IF(condition, messageProvider)                                            \
    const auto _trace_token = condition                                                       \
            ? std::make_optional<android::ScopedTrace>(ATRACE_TAG, messageProvider().c_str()) \
            : std::nullopt
+35 −43
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <utils/Trace.h>

#include <input/InputTransport.h>
#include <input/TraceTools.h>

namespace {

@@ -432,6 +433,10 @@ status_t InputChannel::openInputChannelPair(const std::string& name,
}

status_t InputChannel::sendMessage(const InputMessage* msg) {
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("sendMessage(inputChannel=%s, seq=0x%" PRIx32 ", type=0x%" PRIx32 ")",
                            mName.c_str(), msg->header.seq, msg->header.type);
    });
    const size_t msgLength = msg->size();
    InputMessage cleanMsg;
    msg->getSanitizedCopy(&cleanMsg);
@@ -463,16 +468,13 @@ status_t InputChannel::sendMessage(const InputMessage* msg) {
    ALOGD_IF(DEBUG_CHANNEL_MESSAGES, "channel '%s' ~ sent message of type %s", mName.c_str(),
             ftl::enum_string(msg->header.type).c_str());

    if (ATRACE_ENABLED()) {
        std::string message =
                StringPrintf("sendMessage(inputChannel=%s, seq=0x%" PRIx32 ", type=0x%" PRIx32 ")",
                             mName.c_str(), msg->header.seq, msg->header.type);
        ATRACE_NAME(message.c_str());
    }
    return OK;
}

status_t InputChannel::receiveMessage(InputMessage* msg) {
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("receiveMessage(inputChannel=%s)", mName.c_str());
    });
    ssize_t nRead;
    do {
        nRead = ::recv(getFd(), msg, sizeof(InputMessage), MSG_DONTWAIT);
@@ -504,8 +506,8 @@ status_t InputChannel::receiveMessage(InputMessage* msg) {

    ALOGD_IF(DEBUG_CHANNEL_MESSAGES, "channel '%s' ~ received message of type %s", mName.c_str(),
             ftl::enum_string(msg->header.type).c_str());

    if (ATRACE_ENABLED()) {
        // Add an additional trace point to include data about the received message.
        std::string message = StringPrintf("receiveMessage(inputChannel=%s, seq=0x%" PRIx32
                                           ", type=0x%" PRIx32 ")",
                                           mName.c_str(), msg->header.seq, msg->header.type);
@@ -578,13 +580,11 @@ status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t eventId, int32_t
                                         int32_t flags, int32_t keyCode, int32_t scanCode,
                                         int32_t metaState, int32_t repeatCount, nsecs_t downTime,
                                         nsecs_t eventTime) {
    if (ATRACE_ENABLED()) {
        std::string message =
                StringPrintf("publishKeyEvent(inputChannel=%s, action=%s, keyCode=%s)",
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("publishKeyEvent(inputChannel=%s, action=%s, keyCode=%s)",
                            mChannel->getName().c_str(), KeyEvent::actionToString(action),
                            KeyEvent::getLabel(keyCode));
        ATRACE_NAME(message.c_str());
    }
    });
    ALOGD_IF(debugTransportPublisher(),
             "channel '%s' publisher ~ %s: seq=%u, id=%d, deviceId=%d, source=%s, "
             "action=%s, flags=0x%x, keyCode=%s, scanCode=%d, metaState=0x%x, repeatCount=%d,"
@@ -626,12 +626,11 @@ status_t InputPublisher::publishMotionEvent(
        const ui::Transform& rawTransform, nsecs_t downTime, nsecs_t eventTime,
        uint32_t pointerCount, const PointerProperties* pointerProperties,
        const PointerCoords* pointerCoords) {
    if (ATRACE_ENABLED()) {
        std::string message = StringPrintf("publishMotionEvent(inputChannel=%s, action=%s)",
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("publishMotionEvent(inputChannel=%s, action=%s)",
                            mChannel->getName().c_str(),
                            MotionEvent::actionToString(action).c_str());
        ATRACE_NAME(message.c_str());
    }
    });
    if (verifyEvents()) {
        Result<void> result =
                mInputVerifier.processMovement(deviceId, action, pointerCount, pointerProperties,
@@ -710,11 +709,10 @@ status_t InputPublisher::publishMotionEvent(
}

status_t InputPublisher::publishFocusEvent(uint32_t seq, int32_t eventId, bool hasFocus) {
    if (ATRACE_ENABLED()) {
        std::string message = StringPrintf("publishFocusEvent(inputChannel=%s, hasFocus=%s)",
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("publishFocusEvent(inputChannel=%s, hasFocus=%s)",
                            mChannel->getName().c_str(), toString(hasFocus));
        ATRACE_NAME(message.c_str());
    }
    });
    ALOGD_IF(debugTransportPublisher(), "channel '%s' publisher ~ %s: seq=%u, id=%d, hasFocus=%s",
             mChannel->getName().c_str(), __func__, seq, eventId, toString(hasFocus));

@@ -728,12 +726,10 @@ status_t InputPublisher::publishFocusEvent(uint32_t seq, int32_t eventId, bool h

status_t InputPublisher::publishCaptureEvent(uint32_t seq, int32_t eventId,
                                             bool pointerCaptureEnabled) {
    if (ATRACE_ENABLED()) {
        std::string message =
                StringPrintf("publishCaptureEvent(inputChannel=%s, pointerCaptureEnabled=%s)",
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("publishCaptureEvent(inputChannel=%s, pointerCaptureEnabled=%s)",
                            mChannel->getName().c_str(), toString(pointerCaptureEnabled));
        ATRACE_NAME(message.c_str());
    }
    });
    ALOGD_IF(debugTransportPublisher(),
             "channel '%s' publisher ~ %s: seq=%u, id=%d, pointerCaptureEnabled=%s",
             mChannel->getName().c_str(), __func__, seq, eventId, toString(pointerCaptureEnabled));
@@ -748,12 +744,10 @@ status_t InputPublisher::publishCaptureEvent(uint32_t seq, int32_t eventId,

status_t InputPublisher::publishDragEvent(uint32_t seq, int32_t eventId, float x, float y,
                                          bool isExiting) {
    if (ATRACE_ENABLED()) {
        std::string message =
                StringPrintf("publishDragEvent(inputChannel=%s, x=%f, y=%f, isExiting=%s)",
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("publishDragEvent(inputChannel=%s, x=%f, y=%f, isExiting=%s)",
                            mChannel->getName().c_str(), x, y, toString(isExiting));
        ATRACE_NAME(message.c_str());
    }
    });
    ALOGD_IF(debugTransportPublisher(),
             "channel '%s' publisher ~ %s: seq=%u, id=%d, x=%f, y=%f, isExiting=%s",
             mChannel->getName().c_str(), __func__, seq, eventId, x, y, toString(isExiting));
@@ -769,12 +763,10 @@ status_t InputPublisher::publishDragEvent(uint32_t seq, int32_t eventId, float x
}

status_t InputPublisher::publishTouchModeEvent(uint32_t seq, int32_t eventId, bool isInTouchMode) {
    if (ATRACE_ENABLED()) {
        std::string message =
                StringPrintf("publishTouchModeEvent(inputChannel=%s, isInTouchMode=%s)",
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("publishTouchModeEvent(inputChannel=%s, isInTouchMode=%s)",
                            mChannel->getName().c_str(), toString(isInTouchMode));
        ATRACE_NAME(message.c_str());
    }
    });
    ALOGD_IF(debugTransportPublisher(),
             "channel '%s' publisher ~ %s: seq=%u, id=%d, isInTouchMode=%s",
             mChannel->getName().c_str(), __func__, seq, eventId, toString(isInTouchMode));
+78 −17
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@

#include <android-base/stringprintf.h>
#include <android/log.h>
#include <utils/Trace.h>
#include <input/TraceTools.h>

using android::base::StringPrintf;

@@ -61,58 +61,42 @@ void InputListenerInterface::notify(const NotifyArgs& generalArgs) {

// --- QueuedInputListener ---

static inline void traceEvent(const char* functionName, int32_t id) {
    if (ATRACE_ENABLED()) {
        std::string message = StringPrintf("%s(id=0x%" PRIx32 ")", functionName, id);
        ATRACE_NAME(message.c_str());
    }
}

QueuedInputListener::QueuedInputListener(InputListenerInterface& innerListener)
      : mInnerListener(innerListener) {}

void QueuedInputListener::notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) {
    traceEvent(__func__, args.id);
    mArgsQueue.emplace_back(args);
}

void QueuedInputListener::notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) {
    traceEvent(__func__, args.id);
    mArgsQueue.emplace_back(args);
}

void QueuedInputListener::notifyKey(const NotifyKeyArgs& args) {
    traceEvent(__func__, args.id);
    mArgsQueue.emplace_back(args);
}

void QueuedInputListener::notifyMotion(const NotifyMotionArgs& args) {
    traceEvent(__func__, args.id);
    mArgsQueue.emplace_back(args);
}

void QueuedInputListener::notifySwitch(const NotifySwitchArgs& args) {
    traceEvent(__func__, args.id);
    mArgsQueue.emplace_back(args);
}

void QueuedInputListener::notifySensor(const NotifySensorArgs& args) {
    traceEvent(__func__, args.id);
    mArgsQueue.emplace_back(args);
}

void QueuedInputListener::notifyVibratorState(const NotifyVibratorStateArgs& args) {
    traceEvent(__func__, args.id);
    mArgsQueue.emplace_back(args);
}

void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs& args) {
    traceEvent(__func__, args.id);
    mArgsQueue.emplace_back(args);
}

void QueuedInputListener::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) {
    traceEvent(__func__, args.id);
    mArgsQueue.emplace_back(args);
}

@@ -123,4 +107,81 @@ void QueuedInputListener::flush() {
    mArgsQueue.clear();
}

// --- TracedInputListener ---

TracedInputListener::TracedInputListener(const char* name, InputListenerInterface& innerListener)
      : mInnerListener(innerListener), mName(name) {}

void TracedInputListener::notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) {
    constexpr static auto& fnName = __func__;
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("%s::%s(id=0x%" PRIx32 ")", mName, fnName, args.id);
    });
    mInnerListener.notify(args);
}

void TracedInputListener::notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) {
    constexpr static auto& fnName = __func__;
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("%s::%s(id=0x%" PRIx32 ")", mName, fnName, args.id);
    });
    mInnerListener.notify(args);
}

void TracedInputListener::notifyKey(const NotifyKeyArgs& args) {
    constexpr static auto& fnName = __func__;
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("%s::%s(id=0x%" PRIx32 ")", mName, fnName, args.id);
    });
    mInnerListener.notify(args);
}

void TracedInputListener::notifyMotion(const NotifyMotionArgs& args) {
    constexpr static auto& fnName = __func__;
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("%s::%s(id=0x%" PRIx32 ")", mName, fnName, args.id);
    });
    mInnerListener.notify(args);
}

void TracedInputListener::notifySwitch(const NotifySwitchArgs& args) {
    constexpr static auto& fnName = __func__;
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("%s::%s(id=0x%" PRIx32 ")", mName, fnName, args.id);
    });
    mInnerListener.notify(args);
}

void TracedInputListener::notifySensor(const NotifySensorArgs& args) {
    constexpr static auto& fnName = __func__;
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("%s::%s(id=0x%" PRIx32 ")", mName, fnName, args.id);
    });
    mInnerListener.notify(args);
}

void TracedInputListener::notifyVibratorState(const NotifyVibratorStateArgs& args) {
    constexpr static auto& fnName = __func__;
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("%s::%s(id=0x%" PRIx32 ")", mName, fnName, args.id);
    });
    mInnerListener.notify(args);
}

void TracedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs& args) {
    constexpr static auto& fnName = __func__;
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("%s::%s(id=0x%" PRIx32 ")", mName, fnName, args.id);
    });
    mInnerListener.notify(args);
}

void TracedInputListener::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) {
    constexpr static auto& fnName = __func__;
    ATRACE_NAME_IF(ATRACE_ENABLED(), [&]() {
        return StringPrintf("%s::%s(id=0x%" PRIx32 ")", mName, fnName, args.id);
    });
    mInnerListener.notify(args);
}

} // namespace android
+14 −5
Original line number Diff line number Diff line
@@ -122,15 +122,24 @@ InputManager::InputManager(const sp<InputReaderPolicyInterface>& readerPolicy,
    mInputFlingerRust = createInputFlingerRust();

    mDispatcher = createInputDispatcher(dispatcherPolicy);
    mTracingStages.emplace_back(
            std::make_unique<TracedInputListener>("InputDispatcher", *mDispatcher));

    if (ENABLE_INPUT_DEVICE_USAGE_METRICS) {
        mCollector = std::make_unique<InputDeviceMetricsCollector>(*mDispatcher);
        mCollector = std::make_unique<InputDeviceMetricsCollector>(*mTracingStages.back());
        mTracingStages.emplace_back(
                std::make_unique<TracedInputListener>("MetricsCollector", *mCollector));
    }

    mProcessor = ENABLE_INPUT_DEVICE_USAGE_METRICS ? std::make_unique<InputProcessor>(*mCollector)
                                                   : std::make_unique<InputProcessor>(*mDispatcher);
    mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mProcessor);
    mReader = createInputReader(readerPolicy, *mBlocker);
    mProcessor = std::make_unique<InputProcessor>(*mTracingStages.back());
    mTracingStages.emplace_back(
            std::make_unique<TracedInputListener>("InputProcessor", *mProcessor));

    mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mTracingStages.back());
    mTracingStages.emplace_back(
            std::make_unique<TracedInputListener>("UnwantedInteractionBlocker", *mBlocker));

    mReader = createInputReader(readerPolicy, *mTracingStages.back());
}

InputManager::~InputManager() {
+2 −0
Original line number Diff line number Diff line
@@ -137,6 +137,8 @@ private:
    std::unique_ptr<InputDispatcherInterface> mDispatcher;

    std::shared_ptr<IInputFlingerRust> mInputFlingerRust;

    std::vector<std::unique_ptr<TracedInputListener>> mTracingStages;
};

} // namespace android
Loading