<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[209346] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/209346">209346</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2016-12-05 13:31:23 -0800 (Mon, 05 Dec 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Cocoa] Add some memory usage related information to sysdiagnose state dumps
&lt;https://webkit.org/b/165375&gt;
&lt;rdar://problem/29057243&gt;

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::javaScriptObjectCounts):
(WebCore::PerformanceLogging::didReachPointOfInterest):
* page/PerformanceLogging.h:

Source/WebKit2:

Add two new entries to the sysdiagnose state dumps for WebContent processes:
&quot;Memory Usage Stats&quot; and &quot;JavaScript Object Counts&quot;.

The first category contains all the interesting stuff from task_info()
along with some WebCore and JavaScriptCore 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: &quot;Memory Usage Stats&quot; and &quot;JavaScript Object Counts&quot;.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorepagePerformanceLoggingcpp">trunk/Source/WebCore/page/PerformanceLogging.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePerformanceLoggingh">trunk/Source/WebCore/page/PerformanceLogging.h</a></li>
<li><a href="#trunkSourceWebCorepagecocoaPerformanceLoggingCocoamm">trunk/Source/WebCore/page/cocoa/PerformanceLoggingCocoa.mm</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcesscocoaWebProcessCocoamm">trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (209345 => 209346)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2016-12-05  Andreas Kling  &lt;akling@apple.com&gt;
+
+        [Cocoa] Add some memory usage related information to sysdiagnose state dumps
+        &lt;https://webkit.org/b/165375&gt;
+        &lt;rdar://problem/29057243&gt;
+
+        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::javaScriptObjectCounts):
+        (WebCore::PerformanceLogging::didReachPointOfInterest):
+        * page/PerformanceLogging.h:
+
</ins><span class="cx"> 2016-12-05  Dave Hyatt  &lt;hyatt@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [CSS Parser] Make sure the transform fast path uses WebKitCSSTransformValue
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (209345 => 209346)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -4517,7 +4517,7 @@
</span><span class="cx">                 AD49914318F0815100BF0092 /* HTMLUnknownElement.h in Headers */ = {isa = PBXBuildFile; fileRef = AD49914118F0815100BF0092 /* HTMLUnknownElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 AD5A0C231DECACC000707054 /* PerformanceLoggingCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = AD5A0C221DECA37E00707054 /* PerformanceLoggingCocoa.mm */; };
</span><span class="cx">                 AD5A0C241DECACC400707054 /* PerformanceLogging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD5A0C211DECA10100707054 /* PerformanceLogging.cpp */; };
</span><del>-                AD5A0C251DECACCC00707054 /* PerformanceLogging.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5A0C201DECA0B500707054 /* PerformanceLogging.h */; };
</del><ins>+                AD5A0C251DECACCC00707054 /* PerformanceLogging.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5A0C201DECA0B500707054 /* PerformanceLogging.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 AD6E71AC1668899D00320C13 /* DocumentSharedObjectPool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD6E71AA1668899D00320C13 /* DocumentSharedObjectPool.cpp */; };
</span><span class="cx">                 AD6E71AD1668899D00320C13 /* DocumentSharedObjectPool.h in Headers */ = {isa = PBXBuildFile; fileRef = AD6E71AB1668899D00320C13 /* DocumentSharedObjectPool.h */; };
</span><span class="cx">                 AD726FED16DA1171003A4E6D /* JSCSSStyleDeclarationCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = AD726FEA16D9F40B003A4E6D /* JSCSSStyleDeclarationCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span></span></pre></div>
<a id="trunkSourceWebCorepagePerformanceLoggingcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PerformanceLogging.cpp (209345 => 209346)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -46,19 +46,37 @@
</span><span class="cx">         return &quot;MainFrameLoadCompleted&quot;;
</span><span class="cx">     }
</span><span class="cx"> }
</span><ins>+#endif
</ins><span class="cx"> 
</span><del>-static void getMemoryUsageStatistics(HashMap&lt;const char*, size_t&gt;&amp; stats)
</del><ins>+HashMap&lt;const char*, size_t&gt; PerformanceLogging::memoryUsageStatistics(ShouldIncludeExpensiveComputations includeExpensive)
</ins><span class="cx"> {
</span><ins>+    HashMap&lt;const char*, size_t&gt; stats;
+
</ins><span class="cx">     auto&amp; vm = JSDOMWindow::commonVM();
</span><del>-    stats.set(&quot;javascript_gc_heap_capacity&quot;, vm.heap.capacity());
</del><ins>+    stats.add(&quot;javascript_gc_heap_capacity&quot;, vm.heap.capacity());
+    stats.add(&quot;javascript_gc_heap_extra_memory_size&quot;, vm.heap.extraMemorySize());
</ins><span class="cx"> 
</span><span class="cx">     auto&amp; pageCache = PageCache::singleton();
</span><del>-    stats.set(&quot;pagecache_page_count&quot;, pageCache.pageCount());
</del><ins>+    stats.add(&quot;pagecache_page_count&quot;, pageCache.pageCount());
</ins><span class="cx"> 
</span><del>-    stats.set(&quot;document_count&quot;, Document::allDocuments().size());
</del><ins>+    stats.add(&quot;document_count&quot;, Document::allDocuments().size());
+
+    if (includeExpensive == ShouldIncludeExpensiveComputations::Yes) {
+        stats.add(&quot;javascript_gc_heap_size&quot;, vm.heap.size());
+        stats.add(&quot;javascript_gc_object_count&quot;, vm.heap.objectCount());
+        stats.add(&quot;javascript_gc_protected_object_count&quot;, vm.heap.protectedObjectCount());
+        stats.add(&quot;javascript_gc_global_object_count&quot;, vm.heap.globalObjectCount());
+        stats.add(&quot;javascript_gc_protected_global_object_count&quot;, vm.heap.protectedGlobalObjectCount());
+    }
+
+    return stats;
</ins><span class="cx"> }
</span><del>-#endif
</del><span class="cx"> 
</span><ins>+HashCountedSet&lt;const char*&gt; PerformanceLogging::javaScriptObjectCounts()
+{
+    return *JSDOMWindow::commonVM().heap.objectTypeCounts();
+}
+
</ins><span class="cx"> PerformanceLogging::PerformanceLogging(MainFrame&amp; mainFrame)
</span><span class="cx">     : m_mainFrame(mainFrame)
</span><span class="cx"> {
</span><span class="lines">@@ -73,8 +91,7 @@
</span><span class="cx">     if (m_mainFrame.loader().client().isEmptyFrameLoaderClient())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    HashMap&lt;const char*, size_t&gt; stats;
-    getMemoryUsageStatistics(stats);
</del><ins>+    auto stats = memoryUsageStatistics(ShouldIncludeExpensiveComputations::No);
</ins><span class="cx">     getPlatformMemoryUsageStatistics(stats);
</span><span class="cx"> 
</span><span class="cx">     RELEASE_LOG(PerformanceLogging, &quot;Memory usage info dump at %s:&quot;, toString(poi));
</span></span></pre></div>
<a id="trunkSourceWebCorepagePerformanceLoggingh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PerformanceLogging.h (209345 => 209346)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><ins>+#include &lt;wtf/HashCountedSet.h&gt;
</ins><span class="cx"> #include &lt;wtf/HashMap.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -31,6 +32,8 @@
</span><span class="cx"> 
</span><span class="cx"> class MainFrame;
</span><span class="cx"> 
</span><ins>+enum class ShouldIncludeExpensiveComputations { No, Yes };
+
</ins><span class="cx"> class PerformanceLogging {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(PerformanceLogging);
</span><span class="lines">@@ -41,8 +44,12 @@
</span><span class="cx">         MainFrameLoadStarted,
</span><span class="cx">         MainFrameLoadCompleted,
</span><span class="cx">     };
</span><ins>+
</ins><span class="cx">     void didReachPointOfInterest(PointOfInterest);
</span><span class="cx"> 
</span><ins>+    WEBCORE_EXPORT static HashCountedSet&lt;const char*&gt; javaScriptObjectCounts();
+    WEBCORE_EXPORT static HashMap&lt;const char*, size_t&gt; memoryUsageStatistics(ShouldIncludeExpensiveComputations);
+
</ins><span class="cx"> private:
</span><span class="cx">     static void getPlatformMemoryUsageStatistics(HashMap&lt;const char*, size_t&gt;&amp;);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepagecocoaPerformanceLoggingCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/cocoa/PerformanceLoggingCocoa.mm (209345 => 209346)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -38,11 +38,11 @@
</span><span class="cx">     kern_return_t err = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &amp;vmInfo, &amp;count);
</span><span class="cx">     if (err != KERN_SUCCESS)
</span><span class="cx">         return;
</span><del>-    stats.set(&quot;internal&quot;, static_cast&lt;size_t&gt;(vmInfo.internal));
-    stats.set(&quot;compressed&quot;, static_cast&lt;size_t&gt;(vmInfo.compressed));
-    stats.set(&quot;phys_footprint&quot;, static_cast&lt;size_t&gt;(vmInfo.phys_footprint));
-    stats.set(&quot;resident_size&quot;, static_cast&lt;size_t&gt;(vmInfo.resident_size));
-    stats.set(&quot;virtual_size&quot;, static_cast&lt;size_t&gt;(vmInfo.virtual_size));
</del><ins>+    stats.add(&quot;internal&quot;, static_cast&lt;size_t&gt;(vmInfo.internal));
+    stats.add(&quot;compressed&quot;, static_cast&lt;size_t&gt;(vmInfo.compressed));
+    stats.add(&quot;phys_footprint&quot;, static_cast&lt;size_t&gt;(vmInfo.phys_footprint));
+    stats.add(&quot;resident_size&quot;, static_cast&lt;size_t&gt;(vmInfo.resident_size));
+    stats.add(&quot;virtual_size&quot;, static_cast&lt;size_t&gt;(vmInfo.virtual_size));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (209345 => 209346)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2016-12-05  Andreas Kling  &lt;akling@apple.com&gt;
+
+        [Cocoa] Add some memory usage related information to sysdiagnose state dumps
+        &lt;https://webkit.org/b/165375&gt;
+        &lt;rdar://problem/29057243&gt;
+
+        Reviewed by Darin Adler.
+
+        Add two new entries to the sysdiagnose state dumps for WebContent processes:
+        &quot;Memory Usage Stats&quot; and &quot;JavaScript Object Counts&quot;.
+
+        The first category contains all the interesting stuff from task_info()
+        along with some WebCore and JavaScriptCore 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: &quot;Memory Usage Stats&quot; and &quot;JavaScript Object Counts&quot;.
+
</ins><span class="cx"> 2016-12-05  Csaba Osztrogonác  &lt;ossy@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed cmake buildfix after r209307.
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcesscocoaWebProcessCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm (209345 => 209346)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx"> #import &lt;WebCore/LocalizedStrings.h&gt;
</span><span class="cx"> #import &lt;WebCore/MemoryRelease.h&gt;
</span><span class="cx"> #import &lt;WebCore/NSAccessibilitySPI.h&gt;
</span><ins>+#import &lt;WebCore/PerformanceLogging.h&gt;
</ins><span class="cx"> #import &lt;WebCore/RuntimeApplicationChecks.h&gt;
</span><span class="cx"> #import &lt;WebCore/VNodeTracker.h&gt;
</span><span class="cx"> #import &lt;WebCore/WebCoreNSURLExtras.h&gt;
</span><span class="lines">@@ -194,6 +195,20 @@
</span><span class="cx">             // dictionary will be serialized and passed back to os_state.
</span><span class="cx">             auto stateDict = adoptNS([[NSMutableDictionary alloc] init]);
</span><span class="cx"> 
</span><ins>+            {
+                auto memoryUsageStats = adoptNS([[NSMutableDictionary alloc] init]);
+                for (auto&amp; it : PerformanceLogging::memoryUsageStatistics(ShouldIncludeExpensiveComputations::Yes))
+                    [memoryUsageStats setObject:@(it.value) forKey:[[[NSString alloc] initWithUTF8String:it.key] autorelease]];
+                [stateDict setObject:memoryUsageStats.get() forKey:@&quot;Memory Usage Stats&quot;];
+            }
+
+            {
+                auto jsObjectCounts = adoptNS([[NSMutableDictionary alloc] init]);
+                for (auto&amp; it : PerformanceLogging::javaScriptObjectCounts())
+                    [jsObjectCounts setObject:@(it.value) forKey:[[[NSString alloc] initWithUTF8String:it.key] autorelease]];
+                [stateDict setObject:jsObjectCounts.get() forKey:@&quot;JavaScript Object Counts&quot;];
+            }
+
</ins><span class="cx">             auto pageLoadTimes = adoptNS([[NSMutableArray alloc] init]);
</span><span class="cx">             for (auto&amp; page : m_pageMap.values()) {
</span><span class="cx">                 if (page-&gt;usesEphemeralSession())
</span></span></pre>
</div>
</div>

</body>
</html>