From 399930859a75d806ce0ef124ac22025ae4ef0549 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Thu, 31 May 2012 13:40:27 -0700 Subject: State queue dump Bug: 6591648 Change-Id: Iac75e5ea64e86640b3d890c46a636641b9733c6d --- services/audioflinger/StateQueue.cpp | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'services/audioflinger/StateQueue.cpp') diff --git a/services/audioflinger/StateQueue.cpp b/services/audioflinger/StateQueue.cpp index ae263f5..3e891a5 100644 --- a/services/audioflinger/StateQueue.cpp +++ b/services/audioflinger/StateQueue.cpp @@ -24,12 +24,28 @@ namespace android { +#ifdef STATE_QUEUE_DUMP +void StateQueueObserverDump::dump(int fd) +{ + fdprintf(fd, "State queue observer: stateChanges=%u\n", mStateChanges); +} + +void StateQueueMutatorDump::dump(int fd) +{ + fdprintf(fd, "State queue mutator: pushDirty=%u pushAck=%u blockedSequence=%u\n", + mPushDirty, mPushAck, mBlockedSequence); +} +#endif + // Constructor and destructor template StateQueue::StateQueue() : mNext(NULL), mAck(NULL), mCurrent(NULL), mMutating(&mStates[0]), mExpecting(NULL), mInMutation(false), mIsDirty(false), mIsInitialized(false) +#ifdef STATE_QUEUE_DUMP + , mObserverDump(&mObserverDummyDump), mMutatorDump(&mMutatorDummyDump) +#endif { } @@ -45,6 +61,9 @@ template const T* StateQueue::poll() if (next != mCurrent) { mAck = next; // no additional barrier needed mCurrent = next; +#ifdef STATE_QUEUE_DUMP + mObserverDump->mStateChanges++; +#endif } return next; } @@ -77,10 +96,23 @@ template bool StateQueue::push(StateQueue::block_t block) ALOG_ASSERT(!mInMutation, "push() called when in a mutation"); +#ifdef STATE_QUEUE_DUMP + if (block == BLOCK_UNTIL_ACKED) { + mMutatorDump->mPushAck++; + } +#endif + if (mIsDirty) { +#ifdef STATE_QUEUE_DUMP + mMutatorDump->mPushDirty++; +#endif + // wait for prior push to be acknowledged if (mExpecting != NULL) { +#ifdef STATE_QUEUE_DUMP + unsigned count = 0; +#endif for (;;) { const T *ack = (const T *) mAck; // no additional barrier needed if (ack == mExpecting) { @@ -91,8 +123,19 @@ template bool StateQueue::push(StateQueue::block_t block) if (block == BLOCK_NEVER) { return false; } +#ifdef STATE_QUEUE_DUMP + if (count == 1) { + mMutatorDump->mBlockedSequence++; + } + ++count; +#endif nanosleep(&req, NULL); } +#ifdef STATE_QUEUE_DUMP + if (count > 1) { + mMutatorDump->mBlockedSequence++; + } +#endif } // publish @@ -111,14 +154,28 @@ template bool StateQueue::push(StateQueue::block_t block) // optionally wait for this push or a prior push to be acknowledged if (block == BLOCK_UNTIL_ACKED) { if (mExpecting != NULL) { +#ifdef STATE_QUEUE_DUMP + unsigned count = 0; +#endif for (;;) { const T *ack = (const T *) mAck; // no additional barrier needed if (ack == mExpecting) { mExpecting = NULL; break; } +#ifdef STATE_QUEUE_DUMP + if (count == 1) { + mMutatorDump->mBlockedSequence++; + } + ++count; +#endif nanosleep(&req, NULL); } +#ifdef STATE_QUEUE_DUMP + if (count > 1) { + mMutatorDump->mBlockedSequence++; + } +#endif } } -- cgit v1.1