Bug 1170877 - Track how many times the SurfaceCache has overflowed and report it in about:memory. r=dholbert
authorSeth Fowler <mark.seth.fowler@gmail.com>
Tue, 02 Jun 2015 23:30:11 -0700
changeset 246859 908408ee27c7b384df4c98b5981f97bcbf501574
parent 246858 9d9f124a55a7c144977671de548744ae9c8327fa
child 246860 dd25b4d148af466d9f26930b6e30989fafaa9273
push id60560
push usermfowler@mozilla.com
push dateWed, 03 Jun 2015 06:30:19 +0000
treeherdermozilla-inbound@dd25b4d148af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1170877
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1170877 - Track how many times the SurfaceCache has overflowed and report it in about:memory. r=dholbert
image/SurfaceCache.cpp
--- a/image/SurfaceCache.cpp
+++ b/image/SurfaceCache.cpp
@@ -388,16 +388,17 @@ public:
                    uint32_t aSurfaceCacheSize)
     : mExpirationTracker(aSurfaceCacheExpirationTimeMS)
     , mMemoryPressureObserver(new MemoryPressureObserver)
     , mMutex("SurfaceCache")
     , mDiscardFactor(aSurfaceCacheDiscardFactor)
     , mMaxCost(aSurfaceCacheSize)
     , mAvailableCost(aSurfaceCacheSize)
     , mLockedCost(0)
+    , mOverflowCount(0)
   {
     nsCOMPtr<nsIObserverService> os = services::GetObserverService();
     if (os) {
       os->AddObserver(mMemoryPressureObserver, "memory-pressure", false);
     }
   }
 
 private:
@@ -425,16 +426,17 @@ public:
     // If this is a duplicate surface, refuse to replace the original.
     if (MOZ_UNLIKELY(Lookup(aImageKey, aSurfaceKey))) {
       return InsertOutcome::FAILURE_ALREADY_PRESENT;
     }
 
     // If this is bigger than we can hold after discarding everything we can,
     // refuse to cache it.
     if (MOZ_UNLIKELY(!CanHoldAfterDiscarding(aCost))) {
+      mOverflowCount++;
       return InsertOutcome::FAILURE;
     }
 
     // Remove elements in order of cost until we can fit this in the cache. Note
     // that locked surfaces aren't in mCosts, so we never remove them here.
     while (aCost > mAvailableCost) {
       MOZ_ASSERT(!mCosts.IsEmpty(),
                  "Removed everything and it still won't fit");
@@ -792,16 +794,24 @@ public:
 
     rv = MOZ_COLLECT_REPORT("imagelib-surface-cache-estimated-locked",
                             KIND_OTHER, UNITS_BYTES,
                             mLockedCost,
                             "Estimated memory used by locked surfaces in the "
                             "imagelib surface cache.");
     NS_ENSURE_SUCCESS(rv, rv);
 
+    rv = MOZ_COLLECT_REPORT("imagelib-surface-cache-overflow-count",
+                            KIND_OTHER, UNITS_COUNT,
+                            mOverflowCount,
+                            "Count of how many times the surface cache has hit "
+                            "its capacity and been unable to insert a new "
+                            "surface.");
+    NS_ENSURE_SUCCESS(rv, rv);
+
     return NS_OK;
   }
 
   void CollectSizeOfSurfaces(const ImageKey                  aImageKey,
                              nsTArray<SurfaceMemoryCounter>& aCounters,
                              MallocSizeOf                    aMallocSizeOf)
   {
     nsRefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
@@ -881,16 +891,17 @@ private:
     ImageSurfaceCache> mImageCaches;
   SurfaceTracker                          mExpirationTracker;
   nsRefPtr<MemoryPressureObserver>        mMemoryPressureObserver;
   Mutex                                   mMutex;
   const uint32_t                          mDiscardFactor;
   const Cost                              mMaxCost;
   Cost                                    mAvailableCost;
   Cost                                    mLockedCost;
+  size_t                                  mOverflowCount;
 };
 
 NS_IMPL_ISUPPORTS(SurfaceCacheImpl, nsIMemoryReporter)
 NS_IMPL_ISUPPORTS(SurfaceCacheImpl::MemoryPressureObserver, nsIObserver)
 
 ///////////////////////////////////////////////////////////////////////////////
 // Public API
 ///////////////////////////////////////////////////////////////////////////////