Title: [119722] trunk
Revision
119722
Author
[email protected]
Date
2012-06-07 07:41:31 -0700 (Thu, 07 Jun 2012)

Log Message

Web Inspector: sorting of object fields is broken in heap profiler
https://bugs.webkit.org/show_bug.cgi?id=88532

A recent change to heap profiler has replaced getters with functions.
Function calls were missing in couple places after that change.

Source/WebCore:

Patch by Alexei Filippov <[email protected]> on 2012-06-07
Reviewed by Vsevolod Vlasov.

Tests: inspector/profiler/heap-snapshot-summary-sorting-fields.html
       inspector/profiler/heap-snapshot-summary-sorting-instances.html

* inspector/front-end/HeapSnapshot.js:
(WebInspector.HeapSnapshotEdgesProvider.prototype.sort.compareNodeField):

LayoutTests:

The following changes were made to the tests:
- generateSnapshot now uses pseudo random numbers for object sizes.
  It allows to test sorting.
- Added a test that checks sorting of object instances of a particular class.
- Added a test that checks sorting of fields in an object instance.

Patch by Alexei Filippov <[email protected]> on 2012-06-07
Reviewed by Vsevolod Vlasov.

Tests: inspector/profiler/heap-snapshot-summary-sorting-fields.html
       inspector/profiler/heap-snapshot-summary-sorting-instances.html

* inspector/profiler/heap-snapshot-summary-sorting-fields-expected.txt: Added.
* inspector/profiler/heap-snapshot-summary-sorting-fields.html: Added.
* inspector/profiler/heap-snapshot-summary-sorting-instances-expected.txt: Added.
* inspector/profiler/heap-snapshot-summary-sorting-instances.html: Added.
* inspector/profiler/heap-snapshot-test.js:
(initialize_HeapSnapshotTest.):
(initialize_HeapSnapshotTest):
* platform/mac/Skipped:
* platform/qt/Skipped:
* platform/win/Skipped:
* platform/wincairo/Skipped:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (119721 => 119722)


--- trunk/LayoutTests/ChangeLog	2012-06-07 14:30:56 UTC (rev 119721)
+++ trunk/LayoutTests/ChangeLog	2012-06-07 14:41:31 UTC (rev 119722)
@@ -1,3 +1,34 @@
+2012-06-07  Alexei Filippov  <[email protected]>
+
+        Web Inspector: sorting of object fields is broken in heap profiler
+        https://bugs.webkit.org/show_bug.cgi?id=88532
+
+        A recent change to heap profiler has replaced getters with functions.
+        Function calls were missing in couple places after that change.
+
+        The following changes were made to the tests:
+        - generateSnapshot now uses pseudo random numbers for object sizes.
+          It allows to test sorting.
+        - Added a test that checks sorting of object instances of a particular class.
+        - Added a test that checks sorting of fields in an object instance.
+
+        Reviewed by Vsevolod Vlasov.
+
+        Tests: inspector/profiler/heap-snapshot-summary-sorting-fields.html
+               inspector/profiler/heap-snapshot-summary-sorting-instances.html
+
+        * inspector/profiler/heap-snapshot-summary-sorting-fields-expected.txt: Added.
+        * inspector/profiler/heap-snapshot-summary-sorting-fields.html: Added.
+        * inspector/profiler/heap-snapshot-summary-sorting-instances-expected.txt: Added.
+        * inspector/profiler/heap-snapshot-summary-sorting-instances.html: Added.
+        * inspector/profiler/heap-snapshot-test.js:
+        (initialize_HeapSnapshotTest.):
+        (initialize_HeapSnapshotTest):
+        * platform/mac/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+        * platform/wincairo/Skipped:
+
 2012-06-07  Ilya Tikhonovsky  <[email protected]>
 
         Unreviewed. Clean chromium test expectations.

Added: trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-fields-expected.txt (0 => 119722)


--- trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-fields-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-fields-expected.txt	2012-06-07 14:41:31 UTC (rev 119722)
@@ -0,0 +1,9 @@
+Tests sorting in Summary view of detailed heap snapshots.
+
+Profiler was enabled.
+Detailed heap profiles were enabled.
+
+Running: testSorting
+
+Profiler was disabled.
+
Property changes on: trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-fields-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-fields.html (0 => 119722)


--- trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-fields.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-fields.html	2012-06-07 14:41:31 UTC (rev 119722)
@@ -0,0 +1,91 @@
+<html>
+<head>
+  <script src=""
+  <script src=""
+<script>
+
+function test()
+{
+    var instanceCount = 10;
+    function createHeapSnapshot()
+    {
+        return InspectorTest.createHeapSnapshot(instanceCount);
+    }
+
+    InspectorTest.runHeapSnapshotTestSuite([
+        function testSorting(next)
+        {
+            InspectorTest.takeAndOpenSnapshot(createHeapSnapshot, step1);
+
+            function step1()
+            {
+                InspectorTest.switchToView("Summary", step1a);
+            }
+
+            var columns;
+            var currentColumn;
+            var currentColumnOrder;
+            var windowRow;
+
+            function step1a()
+            {
+                var row = InspectorTest.findRow("object", "Window");
+                InspectorTest.assertEquals(true, !!row, "\"Window\" class row");
+                InspectorTest.expandRow(row, step1b);
+            }
+
+            function step1b(row)
+            {
+                InspectorTest.assertEquals(1, row.children.length, "single Window object");
+                windowRow = row.children[0];
+                InspectorTest.assertEquals(true, !!windowRow, "\"Window\" instance row");
+                InspectorTest.expandRow(windowRow, step2);
+            }
+
+            function step2()
+            {
+                columns = InspectorTest.viewColumns();
+                currentColumn = 0;
+                currentColumnOrder = false;
+                step3();
+            }
+
+            function step3()
+            {
+                if (currentColumn >= columns.length) {
+                    setTimeout(next, 0);
+                    return;
+                }
+                InspectorTest.clickColumn(columns[currentColumn], step4);
+            }
+
+            function step4(newColumnState)
+            {
+                columns[currentColumn] = newColumnState;
+                var columnName = columns[currentColumn].identifier;
+                var contents = windowRow.children.map(function(obj) { return JSON.stringify(obj.data[columnName]); });
+                InspectorTest.assertEquals(instanceCount, contents.length, "column contents");
+                var sortTypes = { object: "text", distanceToWindow: "number", count: "number", shallowSize: "size", retainedSize: "size" };
+                InspectorTest.assertEquals(true, !!sortTypes[columns[currentColumn].identifier], "sort by identifier");
+                InspectorTest.checkArrayIsSorted(contents, sortTypes[columns[currentColumn].identifier], columns[currentColumn].sort);
+
+                if (!currentColumnOrder)
+                    currentColumnOrder = true;
+                else {
+                    currentColumnOrder = false;
+                    ++currentColumn;
+                }
+                step3();
+            }
+        }
+    ]);
+}
+
+</script>
+</head>
+<body _onload_="runTest()">
+<p>
+Tests sorting in Summary view of detailed heap snapshots.
+</p>
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-fields.html
___________________________________________________________________

Added: svn:mime-type

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-instances-expected.txt (0 => 119722)


--- trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-instances-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-instances-expected.txt	2012-06-07 14:41:31 UTC (rev 119722)
@@ -0,0 +1,9 @@
+Tests sorting in Summary view of detailed heap snapshots.
+
+Profiler was enabled.
+Detailed heap profiles were enabled.
+
+Running: testSorting
+
+Profiler was disabled.
+
Property changes on: trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-instances-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-instances.html (0 => 119722)


--- trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-instances.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-instances.html	2012-06-07 14:41:31 UTC (rev 119722)
@@ -0,0 +1,85 @@
+<html>
+<head>
+  <script src=""
+  <script src=""
+<script>
+
+function test()
+{
+    var instanceCount = 10;
+    function createHeapSnapshot()
+    {
+        return InspectorTest.createHeapSnapshot(instanceCount);
+    }
+
+    InspectorTest.runHeapSnapshotTestSuite([
+        function testSorting(next)
+        {
+            InspectorTest.takeAndOpenSnapshot(createHeapSnapshot, step1);
+
+            function step1()
+            {
+                InspectorTest.switchToView("Summary", step1a);
+            }
+
+            var columns;
+            var currentColumn;
+            var currentColumnOrder;
+
+            function step1a()
+            {
+                var row = InspectorTest.findRow("object", "B");
+                InspectorTest.assertEquals(true, !!row, "\"B\" row");
+                InspectorTest.expandRow(row, step2);
+            }
+
+            function step2(row)
+            {
+                columns = InspectorTest.viewColumns();
+                currentColumn = 0;
+                currentColumnOrder = false;
+                step3();
+            }
+
+            function step3()
+            {
+                if (currentColumn >= columns.length) {
+                    setTimeout(next, 0);
+                    return;
+                }
+
+                InspectorTest.clickColumn(columns[currentColumn], step4);
+            }
+
+            function step4(newColumnState)
+            {
+                columns[currentColumn] = newColumnState;
+                var columnName = columns[currentColumn].identifier;
+                var row = InspectorTest.findRow("object", "B");
+                InspectorTest.assertEquals(true, !!row, "\"B\" row");
+                var contents = row.children.map(function(obj) { return JSON.stringify(obj.data[columnName]); });
+                InspectorTest.assertEquals(instanceCount, contents.length, "column contents");
+                var sortTypes = { object: "text", distanceToWindow: "number", count: "number", shallowSize: "size", retainedSize: "size" };
+                InspectorTest.assertEquals(true, !!sortTypes[columns[currentColumn].identifier], "sort by identifier");
+                InspectorTest.checkArrayIsSorted(contents, sortTypes[columns[currentColumn].identifier], columns[currentColumn].sort);
+
+                if (!currentColumnOrder)
+                    currentColumnOrder = true;
+                else {
+                    currentColumnOrder = false;
+                    ++currentColumn;
+                }
+                step3();
+            }
+        }
+    ]);
+}
+
+</script>
+</head>
+<body _onload_="runTest()">
+<p>
+Tests sorting in Summary view of detailed heap snapshots.
+</p>
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/profiler/heap-snapshot-summary-sorting-instances.html
___________________________________________________________________

Added: svn:mime-type

Added: svn:eol-style

Modified: trunk/LayoutTests/inspector/profiler/heap-snapshot-test.js (119721 => 119722)


--- trunk/LayoutTests/inspector/profiler/heap-snapshot-test.js	2012-06-07 14:30:56 UTC (rev 119721)
+++ trunk/LayoutTests/inspector/profiler/heap-snapshot-test.js	2012-06-07 14:41:31 UTC (rev 119722)
@@ -264,42 +264,35 @@
     }
     function parseSize(size)
     {
-        if (size.charAt(0) === ">")
-            size = size.substring(2);
-        var amount = parseFloat(size, 10);
-        var multiplier = {
-            "KB": 1024,
-            "MB": 1024 * 1024
-        }[size.substring(size.length - 2)];
-        return multiplier ? amount * multiplier : amount;
+        if (size.substr(0, 1) === '"') size = JSON.parse(size);
+        // Remove thousands separator.
+        return parseInt(size.replace(/[\u2009,]/g, ""));
     }
-    function extractName(data)
+    function extractField(data, field)
     {
+        if (data.substr(0, 1) !== "{") return data;
         data = ""
-        if (!data.name)
-            InspectorTest.addResult("No name field in " + JSON.stringify(data));
-        return parseInt(data.name, 10);
+        if (!data[field])
+            InspectorTest.addResult("No " + field + " field in " + JSON.stringify(data));
+        return data[field];
     }
     function extractId(data)
     {
-        data = ""
-        if (!data.nodeId)
-            InspectorTest.addResult("No nodeId field in " + JSON.stringify(data));
-        return parseInt(data.nodeId, 10);
+        return parseInt(extractField(data, "nodeId"));
     }
-    var comparator = {
-        text: simpleComparator,
-        number: function (a, b) { return simpleComparator(parseInt(a, 10), parseInt(b, 10)); },
-        size: function (a, b) { return simpleComparator(parseSize(a), parseSize(b)); },
-        name: function (a, b) { return simpleComparator(extractName(a), extractName(b)); },
-        id: function (a, b) { return simpleComparator(extractId(a), extractId(b)); }
+    var extractor = {
+        text: function (data) { return extractField(data, "value"); },
+        number: function (data) { return parseInt(data, 10); },
+        size: function (data) { return parseSize(data); },
+        name: function (data) { return extractField(data, "name"); },
+        id: function (data) { return extractId(data); }
     }[sortType];
     var acceptableComparisonResult = {
         ascending: -1,
         descending: 1
     }[sortOrder];
 
-    if (!comparator) {
+    if (!extractor) {
         InspectorTest.addResult("Invalid sort type: " + sortType);
         return;
     }
@@ -309,9 +302,11 @@
     }
 
     for (var i = 0; i < contents.length - 1; ++i) {
-        var result = comparator(contents[i], contents[i + 1]);
+        var a = extractor(contents[i]);
+        var b = extractor(contents[i + 1]);
+        var result = simpleComparator(a, b);
         if (result !== 0 && result !== acceptableComparisonResult)
-            InspectorTest.addResult("Elements " + i + " and " + (i + 1) + " are out of order: " + contents[i] + " " + contents[i + 1] + " (" + sortOrder + ")");
+            InspectorTest.addResult("Elements " + i + " and " + (i + 1) + " are out of order: " + a + " " + b + " (" + sortOrder + ")");
     }
 };
 
@@ -602,23 +597,29 @@
     // function B(x) { this.a = new A(x); }
     // for (var i = 0; i < instanceCount; ++i) new B();
     // 
-    // Instances of A have 12 bytes size, instances of B has 16 bytes size.
-    var sizeOfA = 12;
-    var sizeOfB = 16;
+    // Set A and B object sizes to pseudo random numbers. It is used in sorting tests.
 
+    var seed = 881669;
+    function pseudoRandom(limit) {
+        seed = ((seed * 355109 + 153763) >> 2) & 0xffff;
+        return seed % limit;
+    }
+
     var builder = new InspectorTest.HeapSnapshotBuilder();
     var rootNode = builder.rootNode;
 
     var gcRootsNode = new InspectorTest.HeapNode("(GC roots)");
     rootNode.linkNode(gcRootsNode, InspectorTest.HeapEdge.Type.element);
 
-    var windowNode = new InspectorTest.HeapNode("Window");
+    var windowNode = new InspectorTest.HeapNode("Window", 20);
     rootNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.shortcut);
     gcRootsNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.element);
 
     for (var i = 0; i < instanceCount; ++i) {
+        var sizeOfB = pseudoRandom(20) + 1;
         var nodeB = new InspectorTest.HeapNode("B", sizeOfB, undefined, firstId++);
         windowNode.linkNode(nodeB, InspectorTest.HeapEdge.Type.element);
+        var sizeOfA = pseudoRandom(50) + 1;
         var nodeA = new InspectorTest.HeapNode("A", sizeOfA, undefined, firstId++);
         nodeB.linkNode(nodeA, InspectorTest.HeapEdge.Type.property, "a");
         nodeA.linkNode(nodeA, InspectorTest.HeapEdge.Type.property, "a");

Modified: trunk/LayoutTests/platform/mac/Skipped (119721 => 119722)


--- trunk/LayoutTests/platform/mac/Skipped	2012-06-07 14:30:56 UTC (rev 119721)
+++ trunk/LayoutTests/platform/mac/Skipped	2012-06-07 14:41:31 UTC (rev 119722)
@@ -287,6 +287,9 @@
 inspector/profiler/heap-snapshot-reveal-in-dominators-view.html
 inspector/profiler/heap-snapshot-summary-retainers.html
 inspector/profiler/heap-snapshot-summary-show-ranges.html
+inspector/profiler/heap-snapshot-summary-sorting-fields.html
+inspector/profiler/heap-snapshot-summary-sorting.html
+inspector/profiler/heap-snapshot-summary-sorting-instances.html
 
 # Skipping newly added tests while I'm finding out what is wrong.
 # https://bugs.webkit.org/show_bug.cgi?id=59706

Modified: trunk/LayoutTests/platform/qt/Skipped (119721 => 119722)


--- trunk/LayoutTests/platform/qt/Skipped	2012-06-07 14:30:56 UTC (rev 119721)
+++ trunk/LayoutTests/platform/qt/Skipped	2012-06-07 14:41:31 UTC (rev 119722)
@@ -284,6 +284,9 @@
 inspector/profiler/heap-snapshot-reveal-in-dominators-view.html
 inspector/profiler/heap-snapshot-summary-retainers.html
 inspector/profiler/heap-snapshot-summary-show-ranges.html
+inspector/profiler/heap-snapshot-summary-sorting-fields.html
+inspector/profiler/heap-snapshot-summary-sorting.html
+inspector/profiler/heap-snapshot-summary-sorting-instances.html
 
 # https://bugs.webkit.org/show_bug.cgi?id=40300
 inspector/debugger/live-edit.html

Modified: trunk/LayoutTests/platform/win/Skipped (119721 => 119722)


--- trunk/LayoutTests/platform/win/Skipped	2012-06-07 14:30:56 UTC (rev 119721)
+++ trunk/LayoutTests/platform/win/Skipped	2012-06-07 14:41:31 UTC (rev 119722)
@@ -1273,6 +1273,9 @@
 inspector/profiler/heap-snapshot-reveal-in-dominators-view.html
 inspector/profiler/heap-snapshot-summary-show-ranges.html
 inspector/profiler/heap-snapshot-summary-retainers.html
+inspector/profiler/heap-snapshot-summary-sorting-fields.html
+inspector/profiler/heap-snapshot-summary-sorting.html
+inspector/profiler/heap-snapshot-summary-sorting-instances.html
 
 # https://bugs.webkit.org/show_bug.cgi?id=40300
 inspector/debugger/live-edit.html

Modified: trunk/LayoutTests/platform/wincairo/Skipped (119721 => 119722)


--- trunk/LayoutTests/platform/wincairo/Skipped	2012-06-07 14:30:56 UTC (rev 119721)
+++ trunk/LayoutTests/platform/wincairo/Skipped	2012-06-07 14:41:31 UTC (rev 119722)
@@ -1772,6 +1772,9 @@
 inspector/profiler/heap-snapshot-reveal-in-dominators-view.html
 inspector/profiler/heap-snapshot-summary-retainers.html
 inspector/profiler/heap-snapshot-summary-show-ranges.html
+inspector/profiler/heap-snapshot-summary-sorting-fields.html
+inspector/profiler/heap-snapshot-summary-sorting.html
+inspector/profiler/heap-snapshot-summary-sorting-instances.html
 
 # https://bugs.webkit.org/show_bug.cgi?id=40300
 inspector/debugger/live-edit.html

Modified: trunk/Source/WebCore/ChangeLog (119721 => 119722)


--- trunk/Source/WebCore/ChangeLog	2012-06-07 14:30:56 UTC (rev 119721)
+++ trunk/Source/WebCore/ChangeLog	2012-06-07 14:41:31 UTC (rev 119722)
@@ -1,3 +1,19 @@
+2012-06-07  Alexei Filippov  <[email protected]>
+
+        Web Inspector: sorting of object fields is broken in heap profiler
+        https://bugs.webkit.org/show_bug.cgi?id=88532
+
+        A recent change to heap profiler has replaced getters with functions.
+        Function calls were missing in couple places after that change.
+
+        Reviewed by Vsevolod Vlasov.
+
+        Tests: inspector/profiler/heap-snapshot-summary-sorting-fields.html
+               inspector/profiler/heap-snapshot-summary-sorting-instances.html
+
+        * inspector/front-end/HeapSnapshot.js:
+        (WebInspector.HeapSnapshotEdgesProvider.prototype.sort.compareNodeField):
+
 2012-06-07  Alexander Pavlov  <[email protected]>
 
         Web Inspector: Consider Ctrl+Shift+key as valid zoom change combinations

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


--- trunk/Source/WebCore/inspector/front-end/HeapSnapshot.js	2012-06-07 14:30:56 UTC (rev 119721)
+++ trunk/Source/WebCore/inspector/front-end/HeapSnapshot.js	2012-06-07 14:41:31 UTC (rev 119722)
@@ -1859,11 +1859,11 @@
         {
             edgeA.edgeIndex = indexA;
             nodeA.nodeIndex = edgeA.nodeIndex();
-            var valueA = nodeA[fieldName];
+            var valueA = nodeA[fieldName]();
 
             edgeB.edgeIndex = indexB;
             nodeB.nodeIndex = edgeB.nodeIndex();
-            var valueB = nodeB[fieldName];
+            var valueB = nodeB[fieldName]();
 
             var result = valueA < valueB ? -1 : (valueA > valueB ? 1 : 0);
             return ascending ? result : -result;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to