Title: [138475] trunk/Source/WebCore
Revision
138475
Author
[email protected]
Date
2012-12-26 04:07:50 -0800 (Wed, 26 Dec 2012)

Log Message

Web Inspector: prepare HeapSnapshot.js for use with native heap snapshot
https://bugs.webkit.org/show_bug.cgi?id=105763

Reviewed by Alexander Pavlov.

HeapSnapshot.js now expects root node to be either the first or the last (real) one
in the list of all nodes.

* inspector/HeapGraphSerializer.cpp:
(HeapGraphNode):
(WebCore::HeapGraphSerializer::serialize): reordered node and edge fields so that the go in
the same order as in the JS heap snapshot.
* inspector/front-end/HeapSnapshot.js:
(WebInspector.HeapSnapshot.prototype._buildAggregates):
(WebInspector.HeapSnapshot.prototype._buildDominatedNodes):
* inspector/front-end/NativeHeapGraph.js:
(WebInspector.NativeHeapGraph):
(WebInspector.NativeHeapGraph.prototype.root): now there is explicit root node which is the last
one in the list, use it.
(WebInspector.NativeHeapGraph.prototype._calculateNodeEdgeIndexes):
(WebInspector.NativeHeapGraph.prototype._addDummyNode): fixed dummy node first edge index.
(WebInspector.NativeHeapGraph.Edge.prototype.target):
(WebInspector.NativeHeapGraph.Node.prototype.referencedNodes):
* inspector/front-end/NativeMemorySnapshotView.js:
(WebInspector.NativeSnapshotNode.prototype._addChildrenFromGraph): switched to use of the root node
(WebInspector.NativeHeapGraphDataGridRoot.prototype._populate):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (138474 => 138475)


--- trunk/Source/WebCore/ChangeLog	2012-12-26 10:27:21 UTC (rev 138474)
+++ trunk/Source/WebCore/ChangeLog	2012-12-26 12:07:50 UTC (rev 138475)
@@ -1,3 +1,32 @@
+2012-12-26  Yury Semikhatsky  <[email protected]>
+
+        Web Inspector: prepare HeapSnapshot.js for use with native heap snapshot
+        https://bugs.webkit.org/show_bug.cgi?id=105763
+
+        Reviewed by Alexander Pavlov.
+
+        HeapSnapshot.js now expects root node to be either the first or the last (real) one
+        in the list of all nodes.
+
+        * inspector/HeapGraphSerializer.cpp:
+        (HeapGraphNode):
+        (WebCore::HeapGraphSerializer::serialize): reordered node and edge fields so that the go in
+        the same order as in the JS heap snapshot.
+        * inspector/front-end/HeapSnapshot.js:
+        (WebInspector.HeapSnapshot.prototype._buildAggregates):
+        (WebInspector.HeapSnapshot.prototype._buildDominatedNodes):
+        * inspector/front-end/NativeHeapGraph.js:
+        (WebInspector.NativeHeapGraph):
+        (WebInspector.NativeHeapGraph.prototype.root): now there is explicit root node which is the last
+        one in the list, use it.
+        (WebInspector.NativeHeapGraph.prototype._calculateNodeEdgeIndexes):
+        (WebInspector.NativeHeapGraph.prototype._addDummyNode): fixed dummy node first edge index.
+        (WebInspector.NativeHeapGraph.Edge.prototype.target):
+        (WebInspector.NativeHeapGraph.Node.prototype.referencedNodes):
+        * inspector/front-end/NativeMemorySnapshotView.js:
+        (WebInspector.NativeSnapshotNode.prototype._addChildrenFromGraph): switched to use of the root node
+        (WebInspector.NativeHeapGraphDataGridRoot.prototype._populate):
+
 2012-12-26  Pan Deng  <[email protected]>
 
         [Web Inspector]Remove Preview and Response tab from network panel in case websocket.

Modified: trunk/Source/WebCore/inspector/HeapGraphSerializer.cpp (138474 => 138475)


--- trunk/Source/WebCore/inspector/HeapGraphSerializer.cpp	2012-12-26 10:27:21 UTC (rev 138474)
+++ trunk/Source/WebCore/inspector/HeapGraphSerializer.cpp	2012-12-26 12:07:50 UTC (rev 138475)
@@ -60,6 +60,7 @@
     int m_className;
     int m_name;
     int m_edgeCount;
+    static const int s_nodeFieldCount = 5;
 };
 
 class HeapGraphEdge {
@@ -158,22 +159,23 @@
 
 PassRefPtr<InspectorObject> HeapGraphSerializer::serialize()
 {
+    addRootNode();
     adjutEdgeTargets();
     RefPtr<InspectorArray> nodes = InspectorArray::create();
     for (size_t i = 0; i < m_nodes.size(); i++) {
         HeapGraphNode& node = m_nodes[i];
         nodes->pushInt(node.m_type);
-        nodes->pushInt(node.m_size);
         nodes->pushInt(node.m_className);
         nodes->pushInt(node.m_name);
+        nodes->pushInt(node.m_size);
         nodes->pushInt(node.m_edgeCount);
     }
     RefPtr<InspectorArray> edges = InspectorArray::create();
     for (size_t i = 0; i < m_edges.size(); i++) {
         HeapGraphEdge& edge = m_edges[i];
         edges->pushInt(edge.m_type);
-        edges->pushInt(edge.m_toIndex);
         edges->pushInt(edge.m_name);
+        edges->pushInt(edge.m_toIndex * HeapGraphNode::s_nodeFieldCount);
     }
     RefPtr<InspectorArray> strings = InspectorArray::create();
     for (size_t i = 0; i < m_strings.size(); i++)

Modified: trunk/Source/WebCore/inspector/front-end/HeapSnapshot.js (138474 => 138475)


--- trunk/Source/WebCore/inspector/front-end/HeapSnapshot.js	2012-12-26 10:27:21 UTC (rev 138474)
+++ trunk/Source/WebCore/inspector/front-end/HeapSnapshot.js	2012-12-26 12:07:50 UTC (rev 138475)
@@ -986,7 +986,7 @@
         var node = new WebInspector.HeapSnapshotNode(this, this._rootNodeIndex);
         var distancesToWindow = this._distancesToWindow;
 
-        for (var nodeIndex = this._rootNodeIndex; nodeIndex < nodesLength; nodeIndex += nodeFieldCount) {
+        for (var nodeIndex = 0; nodeIndex < nodesLength; nodeIndex += nodeFieldCount) {
             var nodeOrdinal = nodeIndex / nodeFieldCount;
             if (!(flags[nodeOrdinal] & pageObjectFlag))
                 continue;
@@ -1316,7 +1316,17 @@
         // index 0) as it is the only node that dominates itself.
         var nodeFieldCount = this._nodeFieldCount;
         var dominatorsTree = this._dominatorsTree;
-        for (var nodeOrdinal = 1, l = this.nodeCount; nodeOrdinal < l; ++nodeOrdinal)
+
+        var fromNodeOrdinal = 0;
+        var toNodeOrdinal = this.nodeCount;
+        var rootNodeOrdinal = this._rootNodeIndex / nodeFieldCount;
+        if (rootNodeOrdinal === fromNodeOrdinal)
+            fromNodeOrdinal = 1;
+        else if (rootNodeOrdinal === toNodeOrdinal - 1)
+            toNodeOrdinal = toNodeOrdinal - 1;
+        else
+            throw new Error("Root node is expected to be either first or last");
+        for (var nodeOrdinal = fromNodeOrdinal; nodeOrdinal < toNodeOrdinal; ++nodeOrdinal)
             ++indexArray[dominatorsTree[nodeOrdinal]];
         // Put in the first slot of each dominatedNodes slice the count of entries
         // that will be filled.
@@ -1329,7 +1339,7 @@
         indexArray[this.nodeCount] = dominatedNodes.length;
         // Fill up the dominatedNodes array with indexes of dominated nodes. Skip the root (node at
         // index 0) as it is the only node that dominates itself.
-        for (var nodeOrdinal = 1, l = this.nodeCount; nodeOrdinal < l; ++nodeOrdinal) {
+        for (var nodeOrdinal = fromNodeOrdinal; nodeOrdinal < toNodeOrdinal; ++nodeOrdinal) {
             var dominatorOrdinal = dominatorsTree[nodeOrdinal];
             var dominatedRefIndex = indexArray[dominatorOrdinal];
             dominatedRefIndex += (--dominatedNodes[dominatedRefIndex]);

Modified: trunk/Source/WebCore/inspector/front-end/NativeHeapGraph.js (138474 => 138475)


--- trunk/Source/WebCore/inspector/front-end/NativeHeapGraph.js	2012-12-26 10:27:21 UTC (rev 138474)
+++ trunk/Source/WebCore/inspector/front-end/NativeHeapGraph.js	2012-12-26 12:07:50 UTC (rev 138475)
@@ -38,44 +38,31 @@
 
     this._nodeFieldCount = 5;
     this._nodeTypeOffset = 0;
-    this._nodeSizeOffset = 1;
-    this._nodeClassNameOffset = 2;
-    this._nodeNameOffset = 3;
+    this._nodeClassNameOffset = 1;
+    this._nodeNameOffset = 2;
+    this._nodeSizeOffset = 3;
     this._nodeEdgeCountOffset = 4;
     this._nodeFirstEdgeOffset = this._nodeEdgeCountOffset;
 
     this._edgeFieldCount = 3;
     this._edgeTypeOffset = 0;
-    this._edgeTargetOffset = 1;
-    this._edgeNameOffset = 2;
+    this._edgeNameOffset = 1;
+    this._edgeTargetOffset = 2;
 
     this._nodeCount = rawGraph.nodes.length / this._nodeFieldCount;
     this._nodes = rawGraph.nodes;
     this._edges = rawGraph.edges;
     this._strings = rawGraph.strings;
 
+    this._rootNodeIndex = this._nodes.length - this._nodeFieldCount;
     this._calculateNodeEdgeIndexes();
+    this._addDummyNode();
 }
 
 WebInspector.NativeHeapGraph.prototype = {
-    rootNodes: function()
+    root: function()
     {
-        var nodeHasIncomingEdges = new Uint8Array(this._nodeCount);
-        var edges = this._edges;
-        var edgesLength = edges.length;
-        var edgeFieldCount = this._edgeFieldCount;
-        var nodeFieldCount = this._nodeFieldCount;
-        for (var i = this._edgeTargetOffset; i < edgesLength; i += edgeFieldCount) {
-            var targetIndex = edges[i];
-            nodeHasIncomingEdges[targetIndex] = 1;
-        }
-        var roots = [];
-        var nodeCount = nodeHasIncomingEdges.length;
-        for (var i = 0; i < nodeCount; i++) {
-            if (!nodeHasIncomingEdges[i])
-                roots.push(new WebInspector.NativeHeapGraph.Node(this, i * nodeFieldCount));
-        }
-        return roots;
+        return new WebInspector.NativeHeapGraph.Node(this, this._rootNodeIndex);
     },
 
     _calculateNodeEdgeIndexes: function()
@@ -89,7 +76,6 @@
             nodes[i] = firstEdgeIndex;
             firstEdgeIndex += count;
         }
-        this._addDummyNode();
     },
 
     _addDummyNode: function()
@@ -97,7 +83,7 @@
         var firstEdgePosition = this._nodes.length + this._nodeFirstEdgeOffset;
         for (var i = 0; i < this._nodeFieldCount; i++)
             this._nodes.push(0);
-        this._nodes[firstEdgePosition] = this._edges.length;
+        this._nodes[firstEdgePosition] = this._edges.length / this._edgeFieldCount;
     }
 }
 
@@ -127,7 +113,7 @@
     target: function()
     {
         var edges = this._graph._edges;
-        var targetPosition = edges[this._position + this._graph._edgeTargetOffset] * this._graph._nodeFieldCount;
+        var targetPosition = edges[this._position + this._graph._edgeTargetOffset];
         return new WebInspector.NativeHeapGraph.Node(this._graph, targetPosition);
     },
 
@@ -198,7 +184,7 @@
         var afterLastEdgePosition = this._afterLastEdgePosition();
         var result = [];
         for (var i = firstEdgePosition + this._graph._edgeTargetOffset; i < afterLastEdgePosition; i += edgeFieldCount)
-            result.push(new WebInspector.NativeHeapGraph.Node(this._graph, edges[i] * nodeFieldCount));
+            result.push(new WebInspector.NativeHeapGraph.Node(this._graph, edges[i]));
         return result;
     },
 

Modified: trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js (138474 => 138475)


--- trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js	2012-12-26 10:27:21 UTC (rev 138474)
+++ trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js	2012-12-26 12:07:50 UTC (rev 138475)
@@ -281,7 +281,7 @@
 
         // Collect objects on the path MemoryCache -> CachedImage -m_image-> BitmapImage -m_frames-> FrameData -m_frame-> SkBitmap -> SkPixelRef
         var graph = this.dataGrid._profile._graph;
-        var roots = graph.rootNodes();
+        var roots = graph.root().referencedNodes();
         var memoryCache;
         for (var i = 0; i < roots.length; i++) {
             var root = roots[i];
@@ -365,7 +365,7 @@
 WebInspector.NativeHeapGraphDataGridRoot.prototype = {
     _populate: function() {
         this.removeEventListener("populate", this._populate, this);
-        var roots = this._graph.rootNodes();
+        var roots = this._graph.root().referencedNodes();
         for (var i = 0; i < roots.length; i++)
             this.appendChild(new WebInspector.NativeHeapGraphDataGridNode(roots[i]));
     },
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to