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

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

Merge "Only log dropped events every two seconds"

parents b2d5156b ae4053f8
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -32,8 +32,9 @@ SensorService::SensorEventConnection::SensorEventConnection(
        const String16& opPackageName, bool hasSensorAccess)
    : mService(service), mUid(uid), mWakeLockRefCount(0), mHasLooperCallbacks(false),
      mDead(false), mDataInjectionMode(isDataInjectionMode), mEventCache(nullptr),
      mCacheSize(0), mMaxCacheSize(0), mPackageName(packageName), mOpPackageName(opPackageName),
      mDestroyed(false), mHasSensorAccess(hasSensorAccess) {
      mCacheSize(0), mMaxCacheSize(0), mTimeOfLastEventDrop(0), mEventsDropped(0),
      mPackageName(packageName), mOpPackageName(opPackageName), mDestroyed(false),
      mHasSensorAccess(hasSensorAccess) {
    mChannel = new BitTube(mService->mSocketBufferSize);
#if DEBUG_CONNECTIONS
    mEventsReceived = mEventsSentFromCache = mEventsSent = 0;
@@ -405,9 +406,6 @@ void SensorService::SensorEventConnection::appendEventsToCacheLocked(sensors_eve
        reAllocateCacheLocked(events, count);
    } else {
        // The events do not fit within the cache: drop the oldest events.
        ALOGW("Dropping events from cache (%d / %d) to save %d newer events", mCacheSize,
                mMaxCacheSize, count);

        int freeSpace = mMaxCacheSize - mCacheSize;

        // Drop up to the currently cached number of events to make room for new events
@@ -419,6 +417,18 @@ void SensorService::SensorEventConnection::appendEventsToCacheLocked(sensors_eve
        // Determine the number of new events to copy into the cache
        int eventsToCopy = std::min(mMaxCacheSize, count);

        constexpr nsecs_t kMinimumTimeBetweenDropLogNs = 2 * 1000 * 1000 * 1000; // 2 sec
        if (events[0].timestamp - mTimeOfLastEventDrop > kMinimumTimeBetweenDropLogNs) {
            ALOGW("Dropping %d cached events (%d/%d) to save %d/%d new events. %d events previously"
                    " dropped", cachedEventsToDrop, mCacheSize, mMaxCacheSize, eventsToCopy,
                    count, mEventsDropped);
            mEventsDropped = 0;
            mTimeOfLastEventDrop = events[0].timestamp;
        } else {
            // Record the number dropped
            mEventsDropped += cachedEventsToDrop + newEventsToDrop;
        }

        // Check for any flush complete events in the events that will be dropped
        countFlushCompleteEventsLocked(mEventCache, cachedEventsToDrop);
        countFlushCompleteEventsLocked(events, newEventsToDrop);
+2 −0
Original line number Diff line number Diff line
@@ -165,6 +165,8 @@ private:

    sensors_event_t *mEventCache;
    int mCacheSize, mMaxCacheSize;
    int64_t mTimeOfLastEventDrop;
    int mEventsDropped;
    String8 mPackageName;
    const String16 mOpPackageName;
#if DEBUG_CONNECTIONS