? threads/.gdb_history Index: threads/nsThread.cpp =================================================================== RCS file: /cvsroot/mozilla/xpcom/threads/nsThread.cpp,v retrieving revision 1.70 diff -u -p -5 -r1.70 nsThread.cpp --- threads/nsThread.cpp 11 Jul 2007 03:01:56 -0000 1.70 +++ threads/nsThread.cpp 25 Aug 2007 15:53:36 -0000 @@ -229,10 +229,15 @@ private: nsThreadShutdownContext *mShutdownContext; }; //----------------------------------------------------------------------------- +// number of latency entries in the buffer before we dump to stderr +#define LATENCY_BUFFER_COUNT 1000 +// below this threshold, we don't bother logging the latency +#define LATENCY_IGNORE_BELOW 10 + /*static*/ void nsThread::ThreadFunc(void *arg) { nsThread *self = static_cast(arg); // strong reference self->mThread = PR_GetCurrentThread(); @@ -248,10 +253,11 @@ nsThread::ThreadFunc(void *arg) } event->Run(); // unblocks nsThread::Init event = nsnull; // Now, process incoming events... + self->mLastServiced = PR_IntervalNow(); while (!self->ShuttingDown()) NS_ProcessNextEvent(self); NS_ProcessPendingEvents(self); @@ -273,17 +279,25 @@ nsThread::nsThread() , mPriority(PRIORITY_NORMAL) , mThread(nsnull) , mRunningEvent(0) , mShutdownContext(nsnull) , mShutdownRequired(PR_FALSE) + , mLatencies(0) + , mLatencyIndex(0) { } nsThread::~nsThread() { if (mLock) PR_DestroyLock(mLock); + if (mLatencies) { + for (int i = 0; i < mLatencyIndex; i++) { + fprintf(stderr, "[LAT] %d\n", PR_IntervalToMilliseconds(mLatencies[i])); + } + free(mLatencies); + } } nsresult nsThread::Init() { @@ -323,10 +337,14 @@ nsThread::Init() nsresult nsThread::InitCurrentThread() { NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY); + mLatencies = (PRIntervalTime *)malloc(sizeof(PRIntervalTime) * LATENCY_BUFFER_COUNT); + NS_ENSURE_TRUE(mLatencies, NS_ERROR_OUT_OF_MEMORY); + fprintf(stderr, "[%p] Latency buffer: %d\n", (void *)this, LATENCY_BUFFER_COUNT); + mThread = PR_GetCurrentThread(); nsThreadManager::get()->RegisterCurrentThread(this); return NS_OK; } @@ -476,12 +494,24 @@ nsThread::ProcessNextEvent(PRBool mayWai if (obs) obs->OnProcessNextEvent(this, mayWait && !ShuttingDown(), mRunningEvent); // If we are shutting down, then do not wait for new events. nsCOMPtr event; + if (mLatencies) { + PRIntervalTime latency = PR_IntervalNow() - mLastServiced; + if (latency >= LATENCY_IGNORE_BELOW) { + mLatencies[mLatencyIndex++] = latency; + if (mLatencyIndex == LATENCY_BUFFER_COUNT) { + for (int i = 0; i < LATENCY_BUFFER_COUNT; i++) { + fprintf(stderr, "[LAT] %d\n", PR_IntervalToMilliseconds(mLatencies[i])); + } + mLatencyIndex = 0; + } + } + } mEvents->GetEvent(mayWait && !ShuttingDown(), getter_AddRefs(event)); - + mLastServiced = PR_IntervalNow(); *result = (event.get() != nsnull); nsresult rv = NS_OK; if (event) { Index: threads/nsThread.h =================================================================== RCS file: /cvsroot/mozilla/xpcom/threads/nsThread.h,v retrieving revision 1.27 diff -u -p -5 -r1.27 nsThread.h --- threads/nsThread.h 11 Jul 2007 00:57:17 -0000 1.27 +++ threads/nsThread.h 25 Aug 2007 15:53:36 -0000 @@ -138,10 +138,13 @@ private: struct nsThreadShutdownContext *mShutdownContext; PRPackedBool mShutdownRequired; PRPackedBool mShutdownPending; + PRIntervalTime *mLatencies; + PRIntervalTime mLastServiced; + int mLatencyIndex; }; //----------------------------------------------------------------------------- class nsThreadSyncDispatch : public nsRunnable {