Bug 1313095 - Preserve cache queue length for logging and telemetry r=honzab
authorMichal Novotny <michal.novotny@gmail.com>
Thu, 10 Nov 2016 16:14:23 +0100
changeset 348739 d6418ae89d3d269bc1bc960886daa95b28dce49a
parent 348738 ce4e1e1d0bff70ea540d62eca9e0720853610700
child 348740 5d98f64b411f8d7708143764bfdb63239d32e921
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1313095
milestone52.0a1
Bug 1313095 - Preserve cache queue length for logging and telemetry r=honzab MozReview-Commit-ID: 2PbkAm78xz8
netwerk/cache2/CacheIOThread.cpp
netwerk/cache2/CacheIOThread.h
--- a/netwerk/cache2/CacheIOThread.cpp
+++ b/netwerk/cache2/CacheIOThread.cpp
@@ -227,16 +227,20 @@ CacheIOThread::CacheIOThread()
 , mHasXPCOMEvents(false)
 , mRerunCurrentEvent(false)
 , mShutdown(false)
 , mIOCancelableEvents(0)
 #ifdef DEBUG
 , mInsideLoop(true)
 #endif
 {
+  for (uint32_t i = 0; i < LAST_LEVEL; ++i) {
+    mQueueLength[i] = 0;
+  }
+
   sSelf = this;
 }
 
 CacheIOThread::~CacheIOThread()
 {
   if (mXPCOMThread) {
     nsIThread *thread = mXPCOMThread;
     thread->Release();
@@ -299,32 +303,35 @@ nsresult CacheIOThread::DispatchAfterPen
 
   MonitorAutoLock lock(mMonitor);
 
   if (mShutdown && (PR_GetCurrentThread() != mThread))
     return NS_ERROR_UNEXPECTED;
 
   // Move everything from later executed OPEN level to the OPEN_PRIORITY level
   // where we post the (eviction) runnable.
+  mQueueLength[OPEN_PRIORITY] += mEventQueue[OPEN].Length();
+  mQueueLength[OPEN] -= mEventQueue[OPEN].Length();
   mEventQueue[OPEN_PRIORITY].AppendElements(mEventQueue[OPEN]);
   mEventQueue[OPEN].Clear();
 
   return DispatchInternal(do_AddRef(aRunnable), OPEN_PRIORITY);
 }
 
 nsresult CacheIOThread::DispatchInternal(already_AddRefed<nsIRunnable> aRunnable,
 					 uint32_t aLevel)
 {
   nsCOMPtr<nsIRunnable> runnable(aRunnable);
 
   if (NS_WARN_IF(!runnable))
     return NS_ERROR_NULL_POINTER;
 
   mMonitor.AssertCurrentThreadOwns();
 
+  ++mQueueLength[aLevel];
   mEventQueue[aLevel].AppendElement(runnable.forget());
   if (mLowestLevelWaiting > aLevel)
     mLowestLevelWaiting = aLevel;
 
   mMonitor.NotifyAll();
 
   return NS_OK;
 }
@@ -538,16 +545,18 @@ void CacheIOThread::LoopOneLevel(uint32_
       mBlockingIOWatcher->NotifyOperationDone();
 
       if (mRerunCurrentEvent) {
         // The event handler yields to higher priority events and wants to rerun.
         returnEvents = true;
         break;
       }
 
+      --mQueueLength[aLevel];
+
       // Release outside the lock.
       events[index] = nullptr;
     }
   }
 
   if (returnEvents)
     mEventQueue[aLevel].InsertElementsAt(0, events.Elements() + index, length - index);
 }
--- a/netwerk/cache2/CacheIOThread.h
+++ b/netwerk/cache2/CacheIOThread.h
@@ -113,16 +113,20 @@ private:
 
   mozilla::Monitor mMonitor;
   PRThread* mThread;
   UniquePtr<detail::BlockingIOWatcher> mBlockingIOWatcher;
   Atomic<nsIThread *> mXPCOMThread;
   Atomic<uint32_t, Relaxed> mLowestLevelWaiting;
   uint32_t mCurrentlyExecutingLevel;
 
+  // Keeps the length of the each event queue, since LoopOneLevel moves all
+  // events into a local array.
+  Atomic<int32_t> mQueueLength[LAST_LEVEL];
+
   EventQueue mEventQueue[LAST_LEVEL];
   // Raised when nsIEventTarget.Dispatch() is called on this thread
   Atomic<bool, Relaxed> mHasXPCOMEvents;
   // See YieldAndRerun() above
   bool mRerunCurrentEvent;
   // Signal to process all pending events and then shutdown
   // Synchronized by mMonitor
   bool mShutdown;