test_memory_allocations_02.html (2082B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Bug 1132764 - Test controlling the maximum allocations log length over the RDP. 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Memory monitoring actor test</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 11 </head> 12 <body> 13 <pre id="test"> 14 <script src="memory-helpers.js" type="application/javascript"></script> 15 <script> 16 "use strict"; 17 18 window.onload = function() { 19 SimpleTest.waitForExplicitFinish(); 20 21 (async function() { 22 const { memory, target } = await startServerAndGetSelectedTabMemory(); 23 await memory.attach(); 24 25 const allocs = []; 26 let eventsFired = 0; 27 let intervalId = null; 28 function onAlloc() { 29 eventsFired++; 30 } 31 function startAllocating() { 32 intervalId = setInterval(() => { 33 for (let i = 100000; --i;) { 34 allocs.push({}); 35 } 36 }, 1); 37 } 38 function stopAllocating() { 39 clearInterval(intervalId); 40 } 41 42 memory.on("allocations", onAlloc); 43 44 await memory.startRecordingAllocations({ 45 drainAllocationsTimeout: 10, 46 }); 47 48 await waitUntil(() => eventsFired > 5); 49 ok(eventsFired > 5, 50 "Some allocation events fired without allocating much via auto drain"); 51 await memory.stopRecordingAllocations(); 52 53 // Set a really high auto drain timer so we can test if 54 // it fires on GC 55 eventsFired = 0; 56 const startTime = performance.now(); 57 const drainTimer = 1000000; 58 await memory.startRecordingAllocations({ 59 drainAllocationsTimeout: drainTimer, 60 }); 61 62 startAllocating(); 63 await waitUntil(() => { 64 Cu.forceGC(); 65 return eventsFired > 1; 66 }); 67 stopAllocating(); 68 ok(performance.now() - drainTimer < startTime, 69 "Allocation events fired on GC before timer"); 70 await memory.stopRecordingAllocations(); 71 72 memory.off("allocations", onAlloc); 73 await memory.detach(); 74 destroyServerAndFinish(target); 75 })(); 76 }; 77 </script> 78 </pre> 79 </body> 80 </html>