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

Commit 4f17282e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Iee0f9a21,I22a39cd5

* changes:
  Move LatencyStatistics collection from InputReader to InputTransport
  Seperate LatencyStatistics from InputReader
parents 8c0f608c 3d3fa52c
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -31,13 +31,16 @@


#include <string>
#include <string>


#include <android-base/chrono_utils.h>

#include <binder/IBinder.h>
#include <binder/IBinder.h>
#include <input/Input.h>
#include <input/Input.h>
#include <input/LatencyStatistics.h>
#include <utils/BitSet.h>
#include <utils/Errors.h>
#include <utils/Errors.h>
#include <utils/Timers.h>
#include <utils/RefBase.h>
#include <utils/RefBase.h>
#include <utils/Timers.h>
#include <utils/Vector.h>
#include <utils/Vector.h>
#include <utils/BitSet.h>


namespace android {
namespace android {
class Parcel;
class Parcel;
@@ -286,7 +289,12 @@ public:
    status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled);
    status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled);


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

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

    void reportTouchEventForStatistics(nsecs_t evdevTime);
};
};


/*
/*
+59 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

#ifndef _UI_INPUT_STATISTICS_H
#define _UI_INPUT_STATISTICS_H

#include <android-base/chrono_utils.h>

#include <stddef.h>

namespace android {

class LatencyStatistics {
private:
    /* Minimum sample recorded */
    float mMin;
    /* Maximum sample recorded */
    float mMax;
    /* Sum of all samples recorded */
    float mSum;
    /* Sum of all the squares of samples recorded */
    float mSum2;
    /* Count of all samples recorded */
    size_t mCount;
    /* The last time statistics were reported */
    std::chrono::steady_clock::time_point mLastReportTime;
    /* Statistics Report Frequency */
    const std::chrono::seconds mReportPeriod;

public:
    LatencyStatistics(std::chrono::seconds period);

    void addValue(float);
    void reset();
    bool shouldReport();

    float getMean();
    float getMin();
    float getMax();
    float getStDev();
    size_t getCount();
};

} // namespace android

#endif // _UI_INPUT_STATISTICS_H
+3 −1
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ cc_library {
                "InputTransport.cpp",
                "InputTransport.cpp",
                "InputWindow.cpp",
                "InputWindow.cpp",
                "ISetInputWindowsListener.cpp",
                "ISetInputWindowsListener.cpp",
                "LatencyStatistics.cpp",
                "VelocityControl.cpp",
                "VelocityControl.cpp",
                "VelocityTracker.cpp",
                "VelocityTracker.cpp",
            ],
            ],
@@ -55,7 +56,8 @@ cc_library {
            shared_libs: [
            shared_libs: [
                "libutils",
                "libutils",
                "libbinder",
                "libbinder",
                "libui"
                "libui",
                "libstatslog",
            ],
            ],


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


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


using android::base::StringPrintf;
using android::base::StringPrintf;


@@ -531,6 +532,10 @@ status_t InputPublisher::publishMotionEvent(
        msg.body.motion.pointers[i].properties.copyFrom(pointerProperties[i]);
        msg.body.motion.pointers[i].properties.copyFrom(pointerProperties[i]);
        msg.body.motion.pointers[i].coords.copyFrom(pointerCoords[i]);
        msg.body.motion.pointers[i].coords.copyFrom(pointerCoords[i]);
    }
    }

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


@@ -557,6 +562,17 @@ status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandle
    return OK;
    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::InputConsumer(const sp<InputChannel>& channel) :
InputConsumer::InputConsumer(const sp<InputChannel>& channel) :
+90 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2019 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 <input/LatencyStatistics.h>

#include <android-base/chrono_utils.h>

#include <cmath>
#include <limits>

namespace android {

LatencyStatistics::LatencyStatistics(std::chrono::seconds period) : mReportPeriod(period) {
    reset();
}

/**
 * Add a raw value to the statistics
 */
void LatencyStatistics::addValue(float value) {
    if (value < mMin) {
        mMin = value;
    }
    if (value > mMax) {
        mMax = value;
    }
    mSum += value;
    mSum2 += value * value;
    mCount++;
}

/**
 * Get the mean. Should not be called if no samples have been added.
 */
float LatencyStatistics::getMean() {
    return mSum / mCount;
}

/**
 * Get the standard deviation. Should not be called if no samples have been added.
 */
float LatencyStatistics::getStDev() {
    float mean = getMean();
    return sqrt(mSum2 / mCount - mean * mean);
}

float LatencyStatistics::getMin() {
    return mMin;
}

float LatencyStatistics::getMax() {
    return mMax;
}

size_t LatencyStatistics::getCount() {
    return mCount;
}

/**
 * Reset internal state. The variable 'when' is the time when the data collection started.
 * Call this to start a new data collection window.
 */
void LatencyStatistics::reset() {
    mMax = std::numeric_limits<float>::lowest();
    mMin = std::numeric_limits<float>::max();
    mSum = 0;
    mSum2 = 0;
    mCount = 0;
    mLastReportTime = std::chrono::steady_clock::now();
}

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

} // namespace android
Loading