Log number of bytes reclaimed at each step of memory pressure relief.
[WebKit-https.git] / Source / WebCore / platform / MemoryPressureHandler.cpp
index 6439614..a3749d8 100644 (file)
@@ -67,32 +67,56 @@ MemoryPressureHandler::MemoryPressureHandler()
 
 void MemoryPressureHandler::releaseMemory(bool critical)
 {
-    int savedPageCacheCapacity = pageCache()->capacity();
-    pageCache()->setCapacity(0);
-    pageCache()->setCapacity(savedPageCacheCapacity);
-
-    fontCache()->purgeInactiveFontData();
-
-    memoryCache()->pruneToPercentage(0);
-
-    cssValuePool().drain();
-
-    clearWidthCaches();
-
-    for (auto* document : Document::allDocuments())
-        document->clearStyleResolver();
-
-    gcController().discardAllCompiledCode();
+    {
+        ReliefLogger log("Empty the PageCache");
+        int savedPageCacheCapacity = pageCache()->capacity();
+        pageCache()->setCapacity(0);
+        pageCache()->setCapacity(savedPageCacheCapacity);
+    }
+
+    {
+        ReliefLogger log("Purge inactive FontData");
+        fontCache()->purgeInactiveFontData();
+    }
+
+    {
+        ReliefLogger log("Prune MemoryCache");
+        memoryCache()->pruneToPercentage(0);
+    }
+
+    {
+        ReliefLogger log("Drain CSSValuePool");
+        cssValuePool().drain();
+    }
+
+    {
+        ReliefLogger log("Clear WidthCaches");
+        clearWidthCaches();
+    }
+
+    {
+        ReliefLogger log("Discard StyleResolvers");
+        for (auto* document : Document::allDocuments())
+            document->clearStyleResolver();
+    }
+
+    {
+        ReliefLogger log("Discard all JIT-compiled code");
+        gcController().discardAllCompiledCode();
+    }
 
     platformReleaseMemory(critical);
 
-    // FastMalloc has lock-free thread specific caches that can only be cleared from the thread itself.
-    StorageThread::releaseFastMallocFreeMemoryInAllThreads();
-    WorkerThread::releaseFastMallocFreeMemoryInAllThreads();
+    {
+        ReliefLogger log("Release free FastMalloc memory");
+        // FastMalloc has lock-free thread specific caches that can only be cleared from the thread itself.
+        StorageThread::releaseFastMallocFreeMemoryInAllThreads();
+        WorkerThread::releaseFastMallocFreeMemoryInAllThreads();
 #if ENABLE(ASYNC_SCROLLING)
-    ScrollingThread::dispatch(bind(WTF::releaseFastMallocFreeMemory));
+        ScrollingThread::dispatch(bind(WTF::releaseFastMallocFreeMemory));
 #endif
-    WTF::releaseFastMallocFreeMemory();
+        WTF::releaseFastMallocFreeMemory();
+    }
 }
 
 #if !PLATFORM(COCOA)
@@ -101,6 +125,8 @@ void MemoryPressureHandler::uninstall() { }
 void MemoryPressureHandler::holdOff(unsigned) { }
 void MemoryPressureHandler::respondToMemoryPressure() { }
 void MemoryPressureHandler::platformReleaseMemory(bool) { }
+void MemoryPressureHandler::ReliefLogger::platformLog() { }
+size_t MemoryPressureHandler::ReliefLogger::platformMemoryUsage() { return 0; }
 #endif
 
 } // namespace WebCore