Title: [196780] trunk/Source/WebCore
Revision
196780
Author
[email protected]
Date
2016-02-18 15:35:42 -0800 (Thu, 18 Feb 2016)

Log Message

Fake memory pressure handler should log detailed memory breakdown.
<https://webkit.org/b/154415>

Reviewed by Antti Koivisto.

Piggyback on the RESOURCE_USAGE code to implement some detailed memory footprint diffing
and have the fake memory handler dump before/after/diff after it runs.

* page/ResourceUsageThread.h:
(WebCore::TagInfo::TagInfo):
* page/cocoa/ResourceUsageThreadCocoa.mm:
(WebCore::logFootprintComparison):
(WebCore::displayNameForVMTag):
(WebCore::pagesPerVMTag):
(WebCore::TagInfo::TagInfo): Deleted.
* platform/cocoa/MemoryPressureHandlerCocoa.mm:
(WebCore::MemoryPressureHandler::install):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (196779 => 196780)


--- trunk/Source/WebCore/ChangeLog	2016-02-18 22:42:54 UTC (rev 196779)
+++ trunk/Source/WebCore/ChangeLog	2016-02-18 23:35:42 UTC (rev 196780)
@@ -1,3 +1,23 @@
+2016-02-18  Andreas Kling  <[email protected]>
+
+        Fake memory pressure handler should log detailed memory breakdown.
+        <https://webkit.org/b/154415>
+
+        Reviewed by Antti Koivisto.
+
+        Piggyback on the RESOURCE_USAGE code to implement some detailed memory footprint diffing
+        and have the fake memory handler dump before/after/diff after it runs.
+
+        * page/ResourceUsageThread.h:
+        (WebCore::TagInfo::TagInfo):
+        * page/cocoa/ResourceUsageThreadCocoa.mm:
+        (WebCore::logFootprintComparison):
+        (WebCore::displayNameForVMTag):
+        (WebCore::pagesPerVMTag):
+        (WebCore::TagInfo::TagInfo): Deleted.
+        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
+        (WebCore::MemoryPressureHandler::install):
+
 2016-02-18  Brady Eidson  <[email protected]>
 
         Modern IDB: Implement server->client operations in WK2.

Modified: trunk/Source/WebCore/page/ResourceUsageThread.h (196779 => 196780)


--- trunk/Source/WebCore/page/ResourceUsageThread.h	2016-02-18 22:42:54 UTC (rev 196779)
+++ trunk/Source/WebCore/page/ResourceUsageThread.h	2016-02-18 23:35:42 UTC (rev 196780)
@@ -29,6 +29,7 @@
 #if ENABLE(RESOURCE_USAGE)
 
 #include "ResourceUsageData.h"
+#include <array>
 #include <functional>
 #include <wtf/Condition.h>
 #include <wtf/HashMap.h>
@@ -72,6 +73,18 @@
     JSC::VM* m_vm { nullptr };
 };
 
+#if PLATFORM(COCOA)
+struct TagInfo {
+    TagInfo() { }
+    size_t dirty { 0 };
+    size_t reclaimable { 0 };
+};
+
+const char* displayNameForVMTag(unsigned);
+std::array<TagInfo, 256> pagesPerVMTag();
+void logFootprintComparison(const std::array<TagInfo, 256>&, const std::array<TagInfo, 256>&);
+#endif
+
 } // namespace WebCore
 
 #endif // ENABLE(RESOURCE_USAGE)

Modified: trunk/Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm (196779 => 196780)


--- trunk/Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm	2016-02-18 22:42:54 UTC (rev 196779)
+++ trunk/Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm	2016-02-18 23:35:42 UTC (rev 196780)
@@ -51,14 +51,60 @@
     return pageSize;
 }
 
-struct TagInfo {
-    TagInfo() { }
-    size_t dirty { 0 };
-    size_t reclaimable { 0 };
-};
+void logFootprintComparison(const std::array<TagInfo, 256>& before, const std::array<TagInfo, 256>& after)
+{
+    const size_t pageSize = vmPageSize();
 
-static std::array<TagInfo, 256> pagesPerVMTag()
+    WTFLogAlways("Per-tag breakdown of memory reclaimed by pressure handler:");
+    WTFLogAlways("  ## %16s %10s %10s %10s", "VM Tag", "Before", "After", "Diff");
+    for (unsigned i = 0; i < 256; ++i) {
+        ssize_t dirtyBefore = before[i].dirty * pageSize;
+        ssize_t dirtyAfter = after[i].dirty * pageSize;
+        ssize_t dirtyDiff = dirtyAfter - dirtyBefore;
+        if (!dirtyBefore && !dirtyAfter)
+            continue;
+        String tagName = displayNameForVMTag(i);
+        if (!tagName)
+            tagName = String::format("Tag %u", i);
+        WTFLogAlways("  %02X %16s %10ld %10ld %10ld",
+            i,
+            tagName.ascii().data(),
+            dirtyBefore,
+            dirtyAfter,
+            dirtyDiff
+        );
+    }
+}
+
+const char* displayNameForVMTag(unsigned tag)
 {
+    switch (tag) {
+    case VM_MEMORY_IOKIT: return "IOKit";
+    case VM_MEMORY_LAYERKIT: return "CoreAnimation";
+    case VM_MEMORY_IMAGEIO: return "ImageIO";
+    case VM_MEMORY_CGIMAGE: return "CG image";
+    case VM_MEMORY_JAVASCRIPT_JIT_EXECUTABLE_ALLOCATOR: return "JSC JIT";
+    case VM_MEMORY_MALLOC: return "malloc";
+    case VM_MEMORY_MALLOC_HUGE: return "malloc (huge)";
+    case VM_MEMORY_MALLOC_LARGE: return "malloc (large)";
+    case VM_MEMORY_MALLOC_SMALL: return "malloc (small)";
+    case VM_MEMORY_MALLOC_TINY: return "malloc (tiny)";
+    case VM_MEMORY_MALLOC_NANO: return "malloc (nano)";
+    case VM_MEMORY_TCMALLOC: return "bmalloc";
+    case VM_MEMORY_FOUNDATION: return "Foundation";
+    case VM_MEMORY_STACK: return "Stack";
+    case VM_MEMORY_SQLITE: return "SQLite";
+    case VM_MEMORY_UNSHARED_PMAP: return "pmap (unshared)";
+    case VM_MEMORY_DYLIB: return "dylib";
+    case VM_MEMORY_CORESERVICES: return "CoreServices";
+    case VM_MEMORY_OS_ALLOC_ONCE: return "os_alloc_once";
+    case VM_MEMORY_LIBDISPATCH: return "libdispatch";
+    default: return nullptr;
+    }
+}
+
+std::array<TagInfo, 256> pagesPerVMTag()
+{
     std::array<TagInfo, 256> tags;
     task_t task = mach_task_self();
     mach_vm_size_t size;

Modified: trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm (196779 => 196780)


--- trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm	2016-02-18 22:42:54 UTC (rev 196779)
+++ trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm	2016-02-18 23:35:42 UTC (rev 196780)
@@ -32,12 +32,14 @@
 #import "JSDOMWindowBase.h"
 #import "LayerPool.h"
 #import "Logging.h"
+#import "ResourceUsageThread.h"
 #import "WebCoreSystemInterface.h"
 #import <mach/mach.h>
 #import <mach/task_info.h>
 #import <malloc/malloc.h>
 #import <notify.h>
 #import <wtf/CurrentTime.h>
+#import <sys/sysctl.h>
 
 #if PLATFORM(IOS)
 #import "SystemMemory.h"
@@ -128,6 +130,10 @@
 
     // Allow simulation of memory pressure with "notifyutil -p org.WebKit.lowMemory"
     notify_register_dispatch("org.WebKit.lowMemory", &_notifyToken, dispatch_get_main_queue(), ^(int) {
+#if ENABLE(RESOURCE_USAGE)
+        auto footprintBefore = pagesPerVMTag();
+#endif
+
         bool wasUnderMemoryPressure = m_underMemoryPressure;
         m_underMemoryPressure = true;
 
@@ -137,6 +143,11 @@
 
         malloc_zone_pressure_relief(nullptr, 0);
 
+#if ENABLE(RESOURCE_USAGE)
+        auto footprintAfter = pagesPerVMTag();
+        logFootprintComparison(footprintBefore, footprintAfter);
+#endif
+
         // Since this is a simulation, unset the "under memory pressure" flag on next runloop.
         dispatch_async(dispatch_get_main_queue(), ^{
             MemoryPressureHandler::singleton().setUnderMemoryPressure(wasUnderMemoryPressure);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to