From e74baf6ca7d57375f38540b6b7ac5e4af019951b Mon Sep 17 00:00:00 2001 From: Aravind Akella Date: Thu, 21 Aug 2014 12:28:35 -0700 Subject: [PATCH] SensorService fixes. i) Add more debug stats (acks needed, acks received) ii) Comment out write failure message. Change-Id: Iac892a66530849a2dd023d6f5628cd070a79537d --- services/sensorservice/SensorService.cpp | 27 ++++++++++++++++++++---- services/sensorservice/SensorService.h | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp index bee506269..84d3b0fc9 100644 --- a/services/sensorservice/SensorService.cpp +++ b/services/sensorservice/SensorService.cpp @@ -924,6 +924,7 @@ SensorService::SensorEventConnection::SensorEventConnection( } #if DEBUG_CONNECTIONS mEventsReceived = mEventsSentFromCache = mEventsSent = 0; + mTotalAcksNeeded = mTotalAcksReceived = 0; #endif } @@ -960,12 +961,15 @@ void SensorService::SensorEventConnection::dump(String8& result) { mCacheSize, mMaxCacheSize); #if DEBUG_CONNECTIONS - result.appendFormat("\t events recvd: %d | sent %d | cache %d | dropped %d\n", + result.appendFormat("\t events recvd: %d | sent %d | cache %d | dropped %d |" + " total_acks_needed %d | total_acks_recvd %d\n", mEventsReceived, mEventsSent, mEventsSentFromCache, - mEventsReceived - (mEventsSentFromCache - mEventsSent + mCacheSize)); + mEventsReceived - (mEventsSentFromCache + + mEventsSent + mCacheSize), + mTotalAcksNeeded, + mTotalAcksReceived); #endif } @@ -1125,6 +1129,9 @@ status_t SensorService::SensorEventConnection::sendEvents( if (index_wake_up_event >= 0) { scratch[index_wake_up_event].flags |= WAKE_UP_SENSOR_EVENT_NEEDS_ACK; ++mWakeLockRefCount; +#if DEBUG_CONNECTIONS + ++mTotalAcksNeeded; +#endif } // NOTE: ASensorEvent and sensors_event_t are the same type. @@ -1136,6 +1143,9 @@ status_t SensorService::SensorEventConnection::sendEvents( // If there was a wake_up sensor_event, reset the flag. scratch[index_wake_up_event].flags &= ~WAKE_UP_SENSOR_EVENT_NEEDS_ACK; --mWakeLockRefCount; +#if DEBUG_CONNECTIONS + --mTotalAcksNeeded; +#endif } if (mEventCache == NULL) { mMaxCacheSize = computeMaxCacheSizeLocked(); @@ -1214,6 +1224,9 @@ void SensorService::SensorEventConnection::writeToSocketFromCacheLocked() { mEventCache[index_wake_up_event + numEventsSent].flags |= WAKE_UP_SENSOR_EVENT_NEEDS_ACK; ++mWakeLockRefCount; +#if DEBUG_CONNECTIONS + ++mTotalAcksNeeded; +#endif } ssize_t size = SensorEventQueue::write(mChannel, @@ -1225,6 +1238,9 @@ void SensorService::SensorEventConnection::writeToSocketFromCacheLocked() { mEventCache[index_wake_up_event + numEventsSent].flags &= ~WAKE_UP_SENSOR_EVENT_NEEDS_ACK; --mWakeLockRefCount; +#if DEBUG_CONNECTIONS + --mTotalAcksNeeded; +#endif } memmove(mEventCache, &mEventCache[numEventsSent], (mCacheSize - numEventsSent) * sizeof(sensors_event_t)); @@ -1333,6 +1349,9 @@ int SensorService::SensorEventConnection::handleEvent(int fd, int events, void* { Mutex::Autolock _l(mConnectionLock); --mWakeLockRefCount; +#if DEBUG_CONNECTIONS + ++mTotalAcksReceived; +#endif } // Check if wakelock can be released by sensorservice. mConnectionLock needs to be released // here as checkWakeLockState() will need it. @@ -1380,7 +1399,7 @@ int SensorService::SensorEventConnection::computeMaxCacheSizeLocked() const { if (fifoWakeUpSensors + fifoNonWakeUpSensors == 0) { // It is extremely unlikely that there is a write failure in non batch mode. Return a cache // size that is equal to that of the batch mode. - ALOGI("Write failure in non-batch mode"); + // ALOGW("Write failure in non-batch mode"); return MAX_SOCKET_BUFFER_SIZE_BATCHED/sizeof(sensors_event_t); } return fifoWakeUpSensors + fifoNonWakeUpSensors; diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h index 15759aefd..77f6f6a1f 100644 --- a/services/sensorservice/SensorService.h +++ b/services/sensorservice/SensorService.h @@ -142,6 +142,7 @@ class SensorService : #if DEBUG_CONNECTIONS int mEventsReceived, mEventsSent, mEventsSentFromCache; + int mTotalAcksNeeded, mTotalAcksReceived; #endif public: