3 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
6 if (window
.testRunner
) {
7 testRunner
.dumpAsText();
8 testRunner
.waitUntilDone();
11 function junkGenerator()
13 var junkArray
= new Array(1000);
14 for (var i
= 0; i
< junkArray
.length
; ++i
)
15 junkArray
[i
] = "42 " + i
;
16 window
.junkArray
= junkArray
;
19 function setupIntervalAndRunTest()
21 setInterval(junkGenerator
, 0);
27 InspectorTest
.importScript("../../../../inspector-protocol/heap-profiler/resources/heap-snapshot-common.js");
29 function trackingStarted()
31 InspectorTest
.log("Tracking started");
34 function arraysEqual(a
, b
)
36 var sa
= a
.join(", ");
37 var sb
= b
.join(", ");
40 InspectorTest
.log("FAIL:\na = [" + sa
+ "]\nb = [" + sb
+ "]");
44 function trackingStopped(snapshot
)
46 var samples
= snapshot
.getSamples();
47 InspectorTest
.log("Last assigned id arrays match: " + arraysEqual(lastAssignedIds
, samples
.lastAssignedIds
));
48 var sizesMatch
= (sizes
.length
<= samples
.sizes
.length
);
49 InspectorTest
.log("Size arrays length is correct: " + sizesMatch
);
52 arraysEqual(sizes
, samples
.sizes
);
54 var sizesNonGrowing
= true;
55 for (var i
= 0; i
< samples
.sizes
.length
; i
++) {
56 if ((sizes
[i
] === undefined && samples
.sizes
[i
] !== 0) || (sizes
[i
] < samples
.sizes
[i
])) {
57 sizesNonGrowing
= false;
58 InspectorTest
.log("FAIL: total size of live objects from interval cannot increase.");
60 arraysEqual(sizes
, samples
.sizes
);
63 InspectorTest
.log("Sizes non growing: " + sizesNonGrowing
);
64 InspectorTest
.completeTest();
68 var lastAssignedIds
= [];
69 InspectorTest
.eventHandler
["HeapProfiler.lastSeenObjectId"] = function(messageObject
)
71 lastAssignedIds
.push(messageObject
["params"]["lastSeenObjectId"]);
72 if (lastAssignedIds
.length
=== 2) {
73 // Wait for two updates and then stop tracing.
74 InspectorTest
.stopRecordingHeapTimeline(trackingStopped
);
78 InspectorTest
.eventHandler
["HeapProfiler.heapStatsUpdate"] = function(messageObject
)
80 var samples
= messageObject
["params"]["statsUpdate"];
81 for (var i
= 0; i
< samples
.length
; i
+= 3) {
83 sizes
[index
] = samples
[i
+2];
87 InspectorTest
.sendCommand("HeapProfiler.startTrackingHeapObjects", {}, trackingStarted
);
88 //@ sourceURL=heap-objects-tracking.html
92 <body onload=
"setupIntervalAndRunTest()">
93 <p>Test that heap tracking actually reports data fragments.
</p>