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

Commit 3dcb58f4 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

EventHub: Log slow reads

Logs slow read times.

A 'slow read' is when the timestamp reported by the kernel is lagging
more than 100ms behind the time when it is being read by
inputflinger.

This will give an indication of if/when input processing in the
InputReader thread is backed up.

Test: Presbumit
Flag: EXEMPT logging only
Bug: 414757227
Change-Id: I73132f09cba414b8145d74c635efbd3088e3b225
parent b2728175
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -86,6 +86,10 @@ static constexpr int32_t FF_WEAK_MAGNITUDE_CHANNEL_IDX = 1;

static constexpr size_t EVENT_BUFFER_SIZE = 256;

// Logs if the difference between the event timestamp and the read time is
// greater than this threshold.
static constexpr nsecs_t SLOW_READ_LOG_THRESHOLD_NS = ms2ns(100);

// Mapping for input battery class node IDs lookup.
// https://www.kernel.org/doc/Documentation/power/power_supply_class.txt
static const std::unordered_map<std::string, InputBatteryClass> BATTERY_CLASSES =
@@ -1997,6 +2001,15 @@ std::vector<RawEvent> EventHub::getEvents(int timeoutMillis) {
                                .code = iev.code,
                                .value = iev.value,
                        });
                        const nsecs_t readDeltaNs = events.back().readTime - events.back().when;
                        if (readDeltaNs >= SLOW_READ_LOG_THRESHOLD_NS) {
                            ALOGW(
                                    "Slow read detected for device '%s', eventTime: %" PRId64 "ns, "
                                    "readDelta: %" PRId64 " ns (over the threshold of %" PRId64
                                    " ms)",
                                    device->identifier.name.c_str(), events.back().when,
                                    readDeltaNs, ns2ms(SLOW_READ_LOG_THRESHOLD_NS));
                        }
                    }
                    if (events.size() >= EVENT_BUFFER_SIZE) {
                        // The result buffer is full.  Reset the pending event index