Changeset 117780 in webkit


Ignore:
Timestamp:
May 21, 2012 7:49:25 AM (12 years ago)
Author:
loislo@chromium.org
Message:

Web Inspector: introduce a helper for HeapSnapshot post-processing tests.
https://bugs.webkit.org/show_bug.cgi?id=87009

the sample:
var builder = new InspectorTest.HeapSnapshotBuilder();
var debuggerNode = new InspectorTest.HeapNode("Debugger");
builder.rootNode.linkNode(debuggerNode, InspectorTest.HeapEdge.Type.element);

var windowNode = new InspectorTest.HeapNode("Window");
builder.rootNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.shortcut);

debuggerNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.property, "windowProperty");
return builder.generateSnapshot();

Reviewed by Yury Semikhatsky.

  • inspector/profiler/heap-snapshot-test.js:

(initialize_HeapSnapshotTest):
(initialize_HeapSnapshotTest.):

  • inspector/profiler/heap-snapshot.html:
Location:
trunk/LayoutTests
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r117776 r117780  
     12012-05-21  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: introduce a helper for HeapSnapshot post-processing tests.
     4        https://bugs.webkit.org/show_bug.cgi?id=87009
     5
     6        the sample:
     7        var builder = new InspectorTest.HeapSnapshotBuilder();
     8        var debuggerNode = new InspectorTest.HeapNode("Debugger");
     9        builder.rootNode.linkNode(debuggerNode, InspectorTest.HeapEdge.Type.element);
     10
     11        var windowNode = new InspectorTest.HeapNode("Window");
     12        builder.rootNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.shortcut);
     13
     14        debuggerNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.property, "windowProperty");
     15        return builder.generateSnapshot();
     16
     17        Reviewed by Yury Semikhatsky.
     18
     19        * inspector/profiler/heap-snapshot-test.js:
     20        (initialize_HeapSnapshotTest):
     21        (initialize_HeapSnapshotTest.):
     22        * inspector/profiler/heap-snapshot.html:
     23
    1242012-05-21  Csaba Osztrogonác  <ossy@webkit.org>
    225
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-expected.txt

    r117749 r117780  
    1818Running: heapSnapshotDominatorsTreeTest
    1919
     20Running: heapSnapshotPageOwnedTest
     21
    2022Running: heapSnapshotRetainersTest
    2123
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-test.js

    r117749 r117780  
    379379};
    380380
     381InspectorTest.HeapNode = function(name, selfSize, type)
     382{
     383    this._type = type ? type : InspectorTest.HeapNode.Type.object;
     384    this._name = name;
     385    this._selfSize = selfSize || 0;
     386    this._builder = null;
     387    this._edges = {};
     388    this._edgesCount = 0;
     389}
     390
     391InspectorTest.HeapNode.Type = {
     392    "hidden": "hidden",
     393    "array": "array",
     394    "string": "string",
     395    "object": "object",
     396    "code": "code",
     397    "closure": "closure",
     398    "regexp": "regexp",
     399    "number": "number",
     400    "native": "native"
     401};
     402
     403InspectorTest.HeapNode.prototype = {
     404    linkNode: function(node, type, nameOrIndex)
     405    {
     406        if (!this._builder)
     407            throw new Error("parent node is not connected to a snapshot");
     408
     409        if (!node._builder)
     410            node._setBuilder(this._builder);
     411
     412        if (nameOrIndex === undefined)
     413            nameOrIndex = this._edgesCount;
     414        ++this._edgesCount;
     415
     416        if (nameOrIndex in this._edges)
     417            throw new Error("Can't add edge with the same nameOrIndex. nameOrIndex: " + nameOrIndex + " oldNodeName: " + this._edges[nameOrIndex]._name + " newNodeName: " + node._name);
     418        this._edges[nameOrIndex] = new InspectorTest.HeapEdge(node, type, nameOrIndex);
     419    },
     420
     421    _setBuilder: function(builder)
     422    {
     423        if (this._builder)
     424            throw new Error("node reusing is prohibited");
     425
     426        this._builder = builder;
     427        this._ordinal = this._builder._registerNode(this);
     428    },
     429
     430    _serialize: function(rawSnapshot)
     431    {
     432        rawSnapshot.nodes.push(this._builder.lookupNodeType(this._type));
     433        rawSnapshot.nodes.push(this._builder.lookupOrAddString(this._name));
     434        // JS engine snapshot impementation generates monotonicaly increasing odd id for JS objects,
     435        // and even ids based on a hash for native DOMObject groups.
     436        rawSnapshot.nodes.push(this._ordinal * 2 + 1);
     437        rawSnapshot.nodes.push(this._selfSize);
     438        rawSnapshot.nodes.push(0);                        // retained_size
     439        rawSnapshot.nodes.push(0);                        // dominator
     440        rawSnapshot.nodes.push(rawSnapshot.edges.length); // edges_index
     441
     442        for (var i in this._edges)
     443            this._edges[i]._serialize(rawSnapshot);
     444    }
     445}
     446
     447InspectorTest.HeapEdge = function(targetNode, type, nameOrIndex)
     448{
     449    this._targetNode = targetNode;
     450    this._type = type;
     451    this._nameOrIndex = nameOrIndex;
     452}
     453
     454InspectorTest.HeapEdge.prototype = {
     455    _serialize: function(rawSnapshot)
     456    {
     457        if (!this._targetNode._builder)
     458            throw new Error("Inconsistent state of node: " + this._name + " no builder assigned");
     459        var builder = this._targetNode._builder;
     460        rawSnapshot.edges.push(builder.lookupEdgeType(this._type));
     461        rawSnapshot.edges.push(typeof this._nameOrIndex === "string" ? builder.lookupOrAddString(this._nameOrIndex) : this._nameOrIndex);
     462        rawSnapshot.edges.push(this._targetNode._ordinal * builder.nodeFieldsCount); // index
     463    }
     464}
     465
     466InspectorTest.HeapEdge.Type = {
     467    "context": "context",
     468    "element": "element",
     469    "property": "property",
     470    "internal": "internal",
     471    "hidden": "hidden",
     472    "shortcut": "shortcut"
     473};
     474
     475InspectorTest.HeapSnapshotBuilder = function()
     476{
     477    this._nodes = [];
     478    this._string2id = {};
     479    this._strings = [];
     480    this.nodeFieldsCount = 7;
     481
     482    this._nodeTypesMap = {};
     483    this._nodeTypesArray = [];
     484    for (var nodeType in InspectorTest.HeapNode.Type) {
     485        this._nodeTypesMap[nodeType] = this._nodeTypesArray.length
     486        this._nodeTypesArray.push(nodeType);
     487    }
     488
     489    this._edgeTypesMap = {};
     490    this._edgeTypesArray = [];
     491    for (var edgeType in InspectorTest.HeapEdge.Type) {
     492        this._edgeTypesMap[edgeType] = this._edgeTypesArray.length
     493        this._edgeTypesArray.push(edgeType);
     494    }
     495
     496    this.rootNode = new InspectorTest.HeapNode("root", 0, "object");
     497    this.rootNode._setBuilder(this);
     498}
     499
     500InspectorTest.HeapSnapshotBuilder.prototype = {
     501    generateSnapshot: function()
     502    {
     503        var rawSnapshot = {
     504            "snapshot": {
     505                "meta": {
     506                    "node_fields": ["type","name","id","self_size","retained_size","dominator","edges_index"],
     507                    "node_types": [
     508                        this._nodeTypesArray,
     509                        "string",
     510                        "number",
     511                        "number",
     512                        "number",
     513                        "number",
     514                        "number"
     515                    ],
     516                    "edge_fields": ["type","name_or_index","to_node"],
     517                    "edge_types": [
     518                        this._edgeTypesArray,
     519                        "string_or_number",
     520                        "node"
     521                    ]
     522                }
     523            },
     524            "nodes": [],
     525            "edges":[],
     526            "strings": [],
     527            maxJSObjectId: this._nodes.length * 2 + 1
     528        };
     529
     530        for (var i = 0; i < this._nodes.length; ++i)
     531            this._nodes[i]._serialize(rawSnapshot);
     532
     533        rawSnapshot.strings = this._strings.slice();
     534
     535        return rawSnapshot;
     536    },
     537
     538    _registerNode: function(node)
     539    {
     540        this._nodes.push(node);
     541        return this._nodes.length - 1;
     542    },
     543
     544    lookupNodeType: function(typeName)
     545    {
     546        if (typeName === undefined)
     547            throw new Error("wrong node type: " + typeName);
     548        if (!typeName in this._nodeTypesMap)
     549            throw new Error("wrong node type name: " + typeName);
     550        return this._nodeTypesMap[typeName];
     551    },
     552
     553    lookupEdgeType: function(typeName)
     554    {
     555        if (!typeName in this._edgeTypesMap)
     556            throw new Error("wrong edge type name: " + typeName);
     557        return this._edgeTypesMap[typeName];
     558    },
     559
     560    lookupOrAddString: function(string)
     561    {
     562        if (string in this._string2id)
     563            return this._string2id[string];
     564        this._string2id[string] = this._strings.length;
     565        this._strings.push(string);
     566        return this._strings.length - 1;
     567    }
     568}
     569
    381570InspectorTest.createHeapSnapshot = function(instanceCount, firstId)
    382571{
  • trunk/LayoutTests/inspector/profiler/heap-snapshot.html

    r117749 r117780  
    114114            for (var i = 0; i < expected.length; ++i)
    115115                InspectorTest.assertEquals(expected[i], dominatorsTree[i], "Dominators Tree");
     116            next();
     117        },
     118
     119        function heapSnapshotPageOwnedTest(next)
     120        {
     121            var builder = new InspectorTest.HeapSnapshotBuilder();
     122            var rootNode = builder.rootNode;
     123
     124            var debuggerNode = new InspectorTest.HeapNode("Debugger");
     125            rootNode.linkNode(debuggerNode, InspectorTest.HeapEdge.Type.element);
     126
     127            var windowNode = new InspectorTest.HeapNode("Window");
     128            rootNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.shortcut);
     129
     130            var pageOwnedNode = new InspectorTest.HeapNode("PageOwnedNode");
     131            windowNode.linkNode(pageOwnedNode, InspectorTest.HeapEdge.Type.element);
     132            debuggerNode.linkNode(pageOwnedNode, InspectorTest.HeapEdge.Type.property, "debugger2pageOwnedNode");
     133
     134            var debuggerOwnedNode = new InspectorTest.HeapNode("debuggerOwnedNode");
     135            debuggerNode.linkNode(debuggerOwnedNode, InspectorTest.HeapEdge.Type.element);
     136
     137            var snapshot = new WebInspector.HeapSnapshot(builder.generateSnapshot());
     138            snapshot._flags = new Array(snapshot.nodeCount);
     139            for (var i = 0; i < snapshot.nodeCount; ++i)
     140                snapshot._flags[i] = 0;
     141            snapshot._markPageOwnedNodes();
     142
     143            var expectedFlags = [0, 0, 4, 4, 0];
     144            InspectorTest.assertEquals(
     145                JSON.stringify(expectedFlags),
     146                JSON.stringify(snapshot._flags),
     147                "We are expecting that only window(third element) and PageOwnedNode(forth element) have flag === 4.");
     148
    116149            next();
    117150        },
Note: See TracChangeset for help on using the changeset viewer.