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

Commit 011ca3db authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Allow debug logging of raw events to be enabled on the fly

Enabling debug logs via adb commands required a reboot of the shell. In
order to debug flaky tests more easily, we allow raw event logs to be
enabled and disabled without the need for a restart on debuggable
builds.

We limit this ability to debuggable builds ensure there is no
performance overhead on user builds.

This change allows us to enable more verbose logging on flaky tests that
are hard to reproduce.

Bug: 193231132
Test: Manual, using adb command to enable debug logs on userdebug builds
Change-Id: I544dbf2ff8258e0bb202653b7ff3d3970f0b752e
parent 0844ed8a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ filegroup {
        "EventHub.cpp",
        "InputDevice.cpp",
        "InputReader.cpp",
        "Macros.cpp",
        "TouchVideoDevice.cpp",
        "controller/PeripheralController.cpp",
        "mapper/CursorInputMapper.cpp",
+3 −3
Original line number Diff line number Diff line
@@ -412,7 +412,7 @@ std::list<NotifyArgs> InputDevice::process(const RawEvent* rawEvents, size_t cou
    // in the order received.
    std::list<NotifyArgs> out;
    for (const RawEvent* rawEvent = rawEvents; count != 0; rawEvent++) {
        if (DEBUG_RAW_EVENTS) {
        if (debugRawEvents()) {
            ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x when=%" PRId64,
                  rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value,
                  rawEvent->when);
@@ -421,11 +421,11 @@ std::list<NotifyArgs> InputDevice::process(const RawEvent* rawEvents, size_t cou
        if (mDropUntilNextSync) {
            if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
                mDropUntilNextSync = false;
                if (DEBUG_RAW_EVENTS) {
                if (debugRawEvents()) {
                    ALOGD("Recovered from input event buffer overrun.");
                }
            } else {
                if (DEBUG_RAW_EVENTS) {
                if (debugRawEvents()) {
                    ALOGD("Dropped input event while waiting for next input sync.");
                }
            }
+2 −2
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ void InputReader::loopOnce() {
        if (mNextTimeout != LLONG_MAX) {
            nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
            if (now >= mNextTimeout) {
                if (DEBUG_RAW_EVENTS) {
                if (debugRawEvents()) {
                    ALOGD("Timeout expired, latency=%0.3fms", (now - mNextTimeout) * 0.000001f);
                }
                mNextTimeout = LLONG_MAX;
@@ -199,7 +199,7 @@ std::list<NotifyArgs> InputReader::processEventsLocked(const RawEvent* rawEvents
                }
                batchSize += 1;
            }
            if (DEBUG_RAW_EVENTS) {
            if (debugRawEvents()) {
                ALOGD("BatchSize: %zu Count: %zu", batchSize, count);
            }
            out += processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.
 */

#include "Macros.h"

#include <android-base/properties.h>

namespace {

const bool IS_DEBUGGABLE_BUILD =
#if defined(__ANDROID__)
        android::base::GetBoolProperty("ro.debuggable", false);
#else
        true;
#endif

} // namespace

namespace android {

bool debugRawEvents() {
    if (!IS_DEBUGGABLE_BUILD) {
        static const bool DEBUG_RAW_EVENTS =
                __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "RawEvents", ANDROID_LOG_INFO);
        return DEBUG_RAW_EVENTS;
    }
    return __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "RawEvents", ANDROID_LOG_INFO);
}

} // namespace android
+7 −3
Original line number Diff line number Diff line
@@ -25,12 +25,14 @@
#include <unordered_map>

namespace android {

/**
 * Log debug messages for each raw event received from the EventHub.
 * Enable this via "adb shell setprop log.tag.InputReaderRawEvents DEBUG" (requires restart)
 * Enable this via "adb shell setprop log.tag.InputReaderRawEvents DEBUG".
 * This requires a restart on non-debuggable (e.g. user) builds, but should take effect immediately
 * on debuggable builds (e.g. userdebug).
 */
const bool DEBUG_RAW_EVENTS =
        __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "RawEvents", ANDROID_LOG_INFO);
bool debugRawEvents();

/**
 * Log debug messages about virtual key processing.
@@ -52,6 +54,7 @@ const bool DEBUG_POINTERS =
 */
const bool DEBUG_POINTER_ASSIGNMENT =
        __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "PointerAssignment", ANDROID_LOG_INFO);

/**
 * Log debug messages about gesture detection.
 * Enable this via "adb shell setprop log.tag.InputReaderGestures DEBUG" (requires restart)
@@ -79,6 +82,7 @@ const bool DEBUG_STYLUS_FUSION =
 */
const bool DEBUG_LIGHT_DETAILS =
        __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "LightDetails", ANDROID_LOG_INFO);

} // namespace android

#define INDENT "  "
Loading