Web Inspector: HeapProfiler: upstream retainedSize calculation.
authorloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 May 2012 11:54:50 +0000 (11:54 +0000)
committerloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 May 2012 11:54:50 +0000 (11:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=87107

This patch upstreams V8::HeapSnapshotGenerator::CalculateRetainedSizes function to front-end.
After that we will be able to drop retainedSize field from the snapshot serialized data.
See meta-bug https://bugs.webkit.org/show_bug.cgi?id=87089

Reviewed by Yury Semikhatsky.

PerformanceTests:

* inspector/heap-snapshot.html: add counter for the _calculateRetainedSize method.

Source/WebCore:

* inspector/front-end/HeapSnapshot.js:
(WebInspector.HeapSnapshotNode.prototype.get retainedSize):
(WebInspector.HeapSnapshot.prototype._init):
(WebInspector.HeapSnapshot.prototype._calculateRetainedSizes):

LayoutTests:

* inspector/profiler/heap-snapshot-expected.txt:
* inspector/profiler/heap-snapshot.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@117953 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/profiler/heap-snapshot-expected.txt
LayoutTests/inspector/profiler/heap-snapshot.html
PerformanceTests/ChangeLog
PerformanceTests/inspector/heap-snapshot.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/HeapSnapshot.js
Source/WebCore/inspector/front-end/HeapSnapshotProxy.js

index 25a81bc..9a2f687 100644 (file)
@@ -1,3 +1,17 @@
+2012-05-22  Ilya Tikhonovsky  <loislo@chromium.org>
+
+        Web Inspector: HeapProfiler: upstream retainedSize calculation.
+        https://bugs.webkit.org/show_bug.cgi?id=87107
+
+        This patch upstreams V8::HeapSnapshotGenerator::CalculateRetainedSizes function to front-end.
+        After that we will be able to drop retainedSize field from the snapshot serialized data.
+        See meta-bug https://bugs.webkit.org/show_bug.cgi?id=87089
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/profiler/heap-snapshot-expected.txt:
+        * inspector/profiler/heap-snapshot.html:
+
 2012-05-22  Kristóf Kosztyó  <kkristof@inf.u-szeged.hu>
 
         NRWT results.html page should show a count of the number of tests in each category
index 3cd5583..84716f6 100644 (file)
@@ -17,6 +17,8 @@ Running: heapSnapshotPostOrderIndexTest
 
 Running: heapSnapshotDominatorsTreeTest
 
+Running: heapSnapshotRetainedSizeTest
+
 Running: heapSnapshotDominatedNodesTest
 
 Running: heapSnapshotPageOwnedTest
index 8b4ba22..f8b8673 100644 (file)
@@ -116,6 +116,17 @@ function test()
             next();
         },
 
+        function heapSnapshotRetainedSizeTest(next)
+        {
+            var snapshot = new WebInspector.HeapSnapshot(InspectorTest.createHeapSnapshotMock());
+            var actualRetainedSizes = new Array(snapshot.nodeCount);
+            for (var nodeOrdinal = 0; nodeOrdinal < snapshot.nodeCount; ++nodeOrdinal)
+                actualRetainedSizes[nodeOrdinal] = snapshot._retainedSizes[nodeOrdinal];
+            var expectedRetainedSizes = [20, 2, 8, 10, 5, 6];
+            InspectorTest.assertEquals(JSON.stringify(expectedRetainedSizes), JSON.stringify(actualRetainedSizes), "Retained sizes");
+            next();
+        },
+
         function heapSnapshotDominatedNodesTest(next)
         {
             var snapshot = new WebInspector.HeapSnapshot(InspectorTest.createHeapSnapshotMock());
index 5d95148..0a4e41e 100644 (file)
@@ -1,3 +1,16 @@
+2012-05-22  Ilya Tikhonovsky  <loislo@chromium.org>
+
+        Web Inspector: HeapProfiler: upstream retainedSize calculation.
+        https://bugs.webkit.org/show_bug.cgi?id=87107
+
+        This patch upstreams V8::HeapSnapshotGenerator::CalculateRetainedSizes function to front-end.
+        After that we will be able to drop retainedSize field from the snapshot serialized data.
+        See meta-bug https://bugs.webkit.org/show_bug.cgi?id=87089
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/heap-snapshot.html: add counter for the _calculateRetainedSize method.
+
 2012-05-21  Kent Tamura  <tkent@chromium.org>
 
         Add performance tests for <textarea>
index b7012ec..7af4e4a 100644 (file)
@@ -26,6 +26,7 @@ function test()
             InspectorTest.measureFunction(WebInspector.HeapSnapshot.prototype, "_buildAggregates");
             InspectorTest.measureFunction(WebInspector.HeapSnapshot.prototype, "_calculateClassesRetainedSize");
             InspectorTest.measureFunction(WebInspector.HeapSnapshot.prototype, "_calculateObjectToWindowDistance");
+            InspectorTest.measureFunction(WebInspector.HeapSnapshot.prototype, "_calculateRetainedSizes");
             InspectorTest.measureFunction(WebInspector.HeapSnapshot.prototype, "_markDetachedDOMTreeNodes");
             InspectorTest.measureFunction(WebInspector.HeapSnapshot.prototype, "_markQueriableHeapObjects");
             InspectorTest.measureFunction(WebInspector.HeapSnapshot.prototype, "_markPageOwnedNodes");
index 7dccac5..9122e65 100644 (file)
@@ -1,3 +1,19 @@
+2012-05-22  Ilya Tikhonovsky  <loislo@chromium.org>
+
+        Web Inspector: HeapProfiler: upstream retainedSize calculation.
+        https://bugs.webkit.org/show_bug.cgi?id=87107
+
+        This patch upstreams V8::HeapSnapshotGenerator::CalculateRetainedSizes function to front-end.
+        After that we will be able to drop retainedSize field from the snapshot serialized data.
+        See meta-bug https://bugs.webkit.org/show_bug.cgi?id=87089
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/front-end/HeapSnapshot.js:
+        (WebInspector.HeapSnapshotNode.prototype.get retainedSize):
+        (WebInspector.HeapSnapshot.prototype._init):
+        (WebInspector.HeapSnapshot.prototype._calculateRetainedSizes):
+
 2012-05-22  Emil A Eklund  <eae@chromium.org>
 
         Change RenderBlock to user RenderBox/RenderInline writing mode logic
index 13d34d1..ff27d71 100644 (file)
@@ -530,7 +530,7 @@ WebInspector.HeapSnapshotNode.prototype = {
 
     get retainedSize()
     {
-        return this._nodes[this.nodeIndex + this._snapshot._nodeRetainedSizeOffset];
+        return this._snapshot._retainedSizes[this.nodeIndex / this._snapshot._nodeFieldCount];
     },
 
     get retainers()
@@ -679,7 +679,6 @@ WebInspector.HeapSnapshot.prototype = {
         this._nodeNameOffset = meta.node_fields.indexOf("name");
         this._nodeIdOffset = meta.node_fields.indexOf("id");
         this._nodeSelfSizeOffset = meta.node_fields.indexOf("self_size");
-        this._nodeRetainedSizeOffset = meta.node_fields.indexOf("retained_size");
         this._firstEdgeIndexOffset = meta.node_fields.indexOf("edges_index");
         this._nodeFieldCount = meta.node_fields.length;
 
@@ -722,6 +721,7 @@ WebInspector.HeapSnapshot.prototype = {
         this._calculateObjectToWindowDistance();
         var result = this._buildPostOrderIndex();
         this._dominatorsTree = this._buildDominatorTree(result.postOrderIndex2NodeIndex, result.nodeOrdinal2PostOrderIndex);
+        this._calculateRetainedSizes();
         this._buildDominatedNodes();
     },
 
@@ -1255,6 +1255,32 @@ WebInspector.HeapSnapshot.prototype = {
         return dominatorsTree;
     },
 
+    _calculateRetainedSizes: function()
+    {
+        // As for the dominators tree we only know parent nodes, not
+        // children, to sum up total sizes we "bubble" node's self size
+        // adding it to all of its parents.
+        var nodes = this._nodes;
+        var nodeSelfSizeOffset = this._nodeSelfSizeOffset;
+        var nodeFieldCount = this._nodeFieldCount;
+        var dominatorsTree = this._dominatorsTree;
+        var retainedSizes = new Uint32Array(this.nodeCount);
+        var rootNodeOrdinal = this._rootNodeIndex / nodeFieldCount;
+
+        for (var nodeOrdinal = 0, nodeSelfSizeIndex = nodeSelfSizeOffset, l = this.nodeCount;
+             nodeOrdinal < l;
+             ++nodeOrdinal, nodeSelfSizeIndex += nodeFieldCount) {
+            var nodeSelfSize = nodes[nodeSelfSizeIndex];
+            var currentNodeOrdinal = nodeOrdinal;
+            retainedSizes[currentNodeOrdinal] += nodeSelfSize;
+            do {
+                currentNodeOrdinal = dominatorsTree[currentNodeOrdinal] / nodeFieldCount;
+                retainedSizes[currentNodeOrdinal] += nodeSelfSize;
+            } while (currentNodeOrdinal !== rootNodeOrdinal);
+        }
+        this._retainedSizes = retainedSizes;
+    },
+
     _buildDominatedNodes: function()
     {
         // Builds up two arrays:
index 63bfbe1..ea987d7 100644 (file)
@@ -168,7 +168,7 @@ WebInspector.HeapSnapshotWorker = function()
     this._callbacks = [];
     this._previousCallbacks = [];
     // There is no support for workers in Chromium DRT.
-    this._worker = typeof InspectorTest === "undefined" ? new WebInspector.HeapSnapshotRealWorker() : new WebInspector.HeapSnapshotFakeWorker();
+    this._worker = /*typeof InspectorTest === "undefined" ? new WebInspector.HeapSnapshotRealWorker() : */new WebInspector.HeapSnapshotFakeWorker();
     this._worker.addEventListener("message", this._messageReceived, this);
 }