Title: [209346] trunk/Source
Revision
209346
Author
[email protected]
Date
2016-12-05 13:31:23 -0800 (Mon, 05 Dec 2016)

Log Message

[Cocoa] Add some memory usage related information to sysdiagnose state dumps
<https://webkit.org/b/165375>
<rdar://problem/29057243>

Reviewed by Darin Adler.

Source/WebCore:

Add a flag to memoryUsageStatistics() to allow gathering of slightly more expensive information.
This mode is used when capturing a state dump for sysdiagnose.

The more expensive information added in this patch relates to information about live objects
and memory on the _javascript_ heap.

* WebCore.xcodeproj/project.pbxproj:
* page/PerformanceLogging.cpp:
(WebCore::PerformanceLogging::memoryUsageStatistics):
(WebCore::PerformanceLogging::_javascript_ObjectCounts):
(WebCore::PerformanceLogging::didReachPointOfInterest):
* page/PerformanceLogging.h:

Source/WebKit2:

Add two new entries to the sysdiagnose state dumps for WebContent processes:
"Memory Usage Stats" and "_javascript_ Object Counts".

The first category contains all the interesting stuff from task_info()
along with some WebCore and _javascript_Core object/memory counters.

The second category contains a list of all the JS object types currently live
on the heap, along with a count.

* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::registerWithStateDumper): Add two new entries to the
state dictionary: "Memory Usage Stats" and "_javascript_ Object Counts".

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (209345 => 209346)


--- trunk/Source/WebCore/ChangeLog	2016-12-05 21:04:29 UTC (rev 209345)
+++ trunk/Source/WebCore/ChangeLog	2016-12-05 21:31:23 UTC (rev 209346)
@@ -1,3 +1,24 @@
+2016-12-05  Andreas Kling  <[email protected]>
+
+        [Cocoa] Add some memory usage related information to sysdiagnose state dumps
+        <https://webkit.org/b/165375>
+        <rdar://problem/29057243>
+
+        Reviewed by Darin Adler.
+
+        Add a flag to memoryUsageStatistics() to allow gathering of slightly more expensive information.
+        This mode is used when capturing a state dump for sysdiagnose.
+
+        The more expensive information added in this patch relates to information about live objects
+        and memory on the _javascript_ heap.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * page/PerformanceLogging.cpp:
+        (WebCore::PerformanceLogging::memoryUsageStatistics):
+        (WebCore::PerformanceLogging::_javascript_ObjectCounts):
+        (WebCore::PerformanceLogging::didReachPointOfInterest):
+        * page/PerformanceLogging.h:
+
 2016-12-05  Dave Hyatt  <[email protected]>
 
         [CSS Parser] Make sure the transform fast path uses WebKitCSSTransformValue

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (209345 => 209346)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-12-05 21:04:29 UTC (rev 209345)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-12-05 21:31:23 UTC (rev 209346)
@@ -4517,7 +4517,7 @@
 		AD49914318F0815100BF0092 /* HTMLUnknownElement.h in Headers */ = {isa = PBXBuildFile; fileRef = AD49914118F0815100BF0092 /* HTMLUnknownElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		AD5A0C231DECACC000707054 /* PerformanceLoggingCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = AD5A0C221DECA37E00707054 /* PerformanceLoggingCocoa.mm */; };
 		AD5A0C241DECACC400707054 /* PerformanceLogging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD5A0C211DECA10100707054 /* PerformanceLogging.cpp */; };
-		AD5A0C251DECACCC00707054 /* PerformanceLogging.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5A0C201DECA0B500707054 /* PerformanceLogging.h */; };
+		AD5A0C251DECACCC00707054 /* PerformanceLogging.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5A0C201DECA0B500707054 /* PerformanceLogging.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		AD6E71AC1668899D00320C13 /* DocumentSharedObjectPool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD6E71AA1668899D00320C13 /* DocumentSharedObjectPool.cpp */; };
 		AD6E71AD1668899D00320C13 /* DocumentSharedObjectPool.h in Headers */ = {isa = PBXBuildFile; fileRef = AD6E71AB1668899D00320C13 /* DocumentSharedObjectPool.h */; };
 		AD726FED16DA1171003A4E6D /* JSCSSStyleDeclarationCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = AD726FEA16D9F40B003A4E6D /* JSCSSStyleDeclarationCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };

Modified: trunk/Source/WebCore/page/PerformanceLogging.cpp (209345 => 209346)


--- trunk/Source/WebCore/page/PerformanceLogging.cpp	2016-12-05 21:04:29 UTC (rev 209345)
+++ trunk/Source/WebCore/page/PerformanceLogging.cpp	2016-12-05 21:31:23 UTC (rev 209346)
@@ -46,19 +46,37 @@
         return "MainFrameLoadCompleted";
     }
 }
+#endif
 
-static void getMemoryUsageStatistics(HashMap<const char*, size_t>& stats)
+HashMap<const char*, size_t> PerformanceLogging::memoryUsageStatistics(ShouldIncludeExpensiveComputations includeExpensive)
 {
+    HashMap<const char*, size_t> stats;
+
     auto& vm = JSDOMWindow::commonVM();
-    stats.set("_javascript__gc_heap_capacity", vm.heap.capacity());
+    stats.add("_javascript__gc_heap_capacity", vm.heap.capacity());
+    stats.add("_javascript__gc_heap_extra_memory_size", vm.heap.extraMemorySize());
 
     auto& pageCache = PageCache::singleton();
-    stats.set("pagecache_page_count", pageCache.pageCount());
+    stats.add("pagecache_page_count", pageCache.pageCount());
 
-    stats.set("document_count", Document::allDocuments().size());
+    stats.add("document_count", Document::allDocuments().size());
+
+    if (includeExpensive == ShouldIncludeExpensiveComputations::Yes) {
+        stats.add("_javascript__gc_heap_size", vm.heap.size());
+        stats.add("_javascript__gc_object_count", vm.heap.objectCount());
+        stats.add("_javascript__gc_protected_object_count", vm.heap.protectedObjectCount());
+        stats.add("_javascript__gc_global_object_count", vm.heap.globalObjectCount());
+        stats.add("_javascript__gc_protected_global_object_count", vm.heap.protectedGlobalObjectCount());
+    }
+
+    return stats;
 }
-#endif
 
+HashCountedSet<const char*> PerformanceLogging::_javascript_ObjectCounts()
+{
+    return *JSDOMWindow::commonVM().heap.objectTypeCounts();
+}
+
 PerformanceLogging::PerformanceLogging(MainFrame& mainFrame)
     : m_mainFrame(mainFrame)
 {
@@ -73,8 +91,7 @@
     if (m_mainFrame.loader().client().isEmptyFrameLoaderClient())
         return;
 
-    HashMap<const char*, size_t> stats;
-    getMemoryUsageStatistics(stats);
+    auto stats = memoryUsageStatistics(ShouldIncludeExpensiveComputations::No);
     getPlatformMemoryUsageStatistics(stats);
 
     RELEASE_LOG(PerformanceLogging, "Memory usage info dump at %s:", toString(poi));

Modified: trunk/Source/WebCore/page/PerformanceLogging.h (209345 => 209346)


--- trunk/Source/WebCore/page/PerformanceLogging.h	2016-12-05 21:04:29 UTC (rev 209345)
+++ trunk/Source/WebCore/page/PerformanceLogging.h	2016-12-05 21:31:23 UTC (rev 209346)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include <wtf/HashCountedSet.h>
 #include <wtf/HashMap.h>
 
 namespace WebCore {
@@ -31,6 +32,8 @@
 
 class MainFrame;
 
+enum class ShouldIncludeExpensiveComputations { No, Yes };
+
 class PerformanceLogging {
     WTF_MAKE_FAST_ALLOCATED;
     WTF_MAKE_NONCOPYABLE(PerformanceLogging);
@@ -41,8 +44,12 @@
         MainFrameLoadStarted,
         MainFrameLoadCompleted,
     };
+
     void didReachPointOfInterest(PointOfInterest);
 
+    WEBCORE_EXPORT static HashCountedSet<const char*> _javascript_ObjectCounts();
+    WEBCORE_EXPORT static HashMap<const char*, size_t> memoryUsageStatistics(ShouldIncludeExpensiveComputations);
+
 private:
     static void getPlatformMemoryUsageStatistics(HashMap<const char*, size_t>&);
 

Modified: trunk/Source/WebCore/page/cocoa/PerformanceLoggingCocoa.mm (209345 => 209346)


--- trunk/Source/WebCore/page/cocoa/PerformanceLoggingCocoa.mm	2016-12-05 21:04:29 UTC (rev 209345)
+++ trunk/Source/WebCore/page/cocoa/PerformanceLoggingCocoa.mm	2016-12-05 21:31:23 UTC (rev 209346)
@@ -38,11 +38,11 @@
     kern_return_t err = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);
     if (err != KERN_SUCCESS)
         return;
-    stats.set("internal", static_cast<size_t>(vmInfo.internal));
-    stats.set("compressed", static_cast<size_t>(vmInfo.compressed));
-    stats.set("phys_footprint", static_cast<size_t>(vmInfo.phys_footprint));
-    stats.set("resident_size", static_cast<size_t>(vmInfo.resident_size));
-    stats.set("virtual_size", static_cast<size_t>(vmInfo.virtual_size));
+    stats.add("internal", static_cast<size_t>(vmInfo.internal));
+    stats.add("compressed", static_cast<size_t>(vmInfo.compressed));
+    stats.add("phys_footprint", static_cast<size_t>(vmInfo.phys_footprint));
+    stats.add("resident_size", static_cast<size_t>(vmInfo.resident_size));
+    stats.add("virtual_size", static_cast<size_t>(vmInfo.virtual_size));
 }
 
 }

Modified: trunk/Source/WebKit2/ChangeLog (209345 => 209346)


--- trunk/Source/WebKit2/ChangeLog	2016-12-05 21:04:29 UTC (rev 209345)
+++ trunk/Source/WebKit2/ChangeLog	2016-12-05 21:31:23 UTC (rev 209346)
@@ -1,3 +1,24 @@
+2016-12-05  Andreas Kling  <[email protected]>
+
+        [Cocoa] Add some memory usage related information to sysdiagnose state dumps
+        <https://webkit.org/b/165375>
+        <rdar://problem/29057243>
+
+        Reviewed by Darin Adler.
+
+        Add two new entries to the sysdiagnose state dumps for WebContent processes:
+        "Memory Usage Stats" and "_javascript_ Object Counts".
+
+        The first category contains all the interesting stuff from task_info()
+        along with some WebCore and _javascript_Core object/memory counters.
+
+        The second category contains a list of all the JS object types currently live
+        on the heap, along with a count.
+
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::registerWithStateDumper): Add two new entries to the
+        state dictionary: "Memory Usage Stats" and "_javascript_ Object Counts".
+
 2016-12-05  Csaba Osztrogonác  <[email protected]>
 
         Unreviewed cmake buildfix after r209307.

Modified: trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm (209345 => 209346)


--- trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm	2016-12-05 21:04:29 UTC (rev 209345)
+++ trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm	2016-12-05 21:31:23 UTC (rev 209346)
@@ -51,6 +51,7 @@
 #import <WebCore/LocalizedStrings.h>
 #import <WebCore/MemoryRelease.h>
 #import <WebCore/NSAccessibilitySPI.h>
+#import <WebCore/PerformanceLogging.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/VNodeTracker.h>
 #import <WebCore/WebCoreNSURLExtras.h>
@@ -194,6 +195,20 @@
             // dictionary will be serialized and passed back to os_state.
             auto stateDict = adoptNS([[NSMutableDictionary alloc] init]);
 
+            {
+                auto memoryUsageStats = adoptNS([[NSMutableDictionary alloc] init]);
+                for (auto& it : PerformanceLogging::memoryUsageStatistics(ShouldIncludeExpensiveComputations::Yes))
+                    [memoryUsageStats setObject:@(it.value) forKey:[[[NSString alloc] initWithUTF8String:it.key] autorelease]];
+                [stateDict setObject:memoryUsageStats.get() forKey:@"Memory Usage Stats"];
+            }
+
+            {
+                auto jsObjectCounts = adoptNS([[NSMutableDictionary alloc] init]);
+                for (auto& it : PerformanceLogging::_javascript_ObjectCounts())
+                    [jsObjectCounts setObject:@(it.value) forKey:[[[NSString alloc] initWithUTF8String:it.key] autorelease]];
+                [stateDict setObject:jsObjectCounts.get() forKey:@"_javascript_ Object Counts"];
+            }
+
             auto pageLoadTimes = adoptNS([[NSMutableArray alloc] init]);
             for (auto& page : m_pageMap.values()) {
                 if (page->usesEphemeralSession())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to