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

Commit de4bf150 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Do not report latency for injected events

When reporting the latency of touch events, ensure that injected events
are excluded. These events can have arbitrary timestamps, and would not
result in meaningful data. Also do not report events for statistics if
inputfilter is enabled.

Move the statistics reporting from InputTransport to InputDispatcher.
This ensures that there's only 1 instance of the mStatistics object.
This also provides easy access to the inputfilterenabled state.

Bug: 13894199
Test: Change the reporting period to 0 (to report every event immediately)
Inject events in various ways and ensure they don't go to statsd
$ m statsd_testdrive && ./out/host/linux-x86/bin/statsd_testdrive 34
$ adb shell input tap 100 100
$ adb shell monkey 1000
Next, relaunch the statsd_testdrive script and touch the screen
Observe that events are reported.

Change-Id: Ief8040599a347e084e75584ed3164c60a6dbc4ad
parent 6cd19a42
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@

#include <binder/IBinder.h>
#include <input/Input.h>
#include <input/LatencyStatistics.h>
#include <utils/BitSet.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
@@ -289,12 +288,8 @@ public:
    status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled);

private:
    static constexpr std::chrono::duration TOUCH_STATS_REPORT_PERIOD = 5min;

    sp<InputChannel> mChannel;
    LatencyStatistics mTouchStatistics{TOUCH_STATS_REPORT_PERIOD};

    void reportTouchEventForStatistics(nsecs_t evdevTime);
};

/*
+0 −1
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ cc_library {
                "libutils",
                "libbinder",
                "libui",
                "libstatslog",
            ],

            sanitize: {
+0 −15
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
#include <utils/Trace.h>

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

using android::base::StringPrintf;

@@ -538,9 +537,6 @@ status_t InputPublisher::publishMotionEvent(
        msg.body.motion.pointers[i].coords.copyFrom(pointerCoords[i]);
    }

    if (source == AINPUT_SOURCE_TOUCHSCREEN) {
        reportTouchEventForStatistics(eventTime);
    }
    return mChannel->sendMessage(&msg);
}

@@ -567,17 +563,6 @@ status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandle
    return OK;
}

void InputPublisher::reportTouchEventForStatistics(nsecs_t evdevTime) {
    if (mTouchStatistics.shouldReport()) {
        android::util::stats_write(android::util::TOUCH_EVENT_REPORTED, mTouchStatistics.getMin(),
                                   mTouchStatistics.getMax(), mTouchStatistics.getMean(),
                                   mTouchStatistics.getStDev(), mTouchStatistics.getCount());
        mTouchStatistics.reset();
    }
    nsecs_t latency = nanoseconds_to_microseconds(systemTime(CLOCK_MONOTONIC) - evdevTime);
    mTouchStatistics.addValue(latency);
}

// --- InputConsumer ---

InputConsumer::InputConsumer(const sp<InputChannel>& channel) :
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ void LatencyStatistics::reset() {

bool LatencyStatistics::shouldReport() {
    std::chrono::duration timeSinceReport = std::chrono::steady_clock::now() - mLastReportTime;
    return mCount != 0 && timeSinceReport > mReportPeriod;
    return mCount != 0 && timeSinceReport >= mReportPeriod;
}

} // namespace android
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ cc_library_shared {
        "libhidlbase",
        "libinput",
        "liblog",
        "libstatslog",
        "libutils",
        "libui",
        "server_configurable_flags",
Loading