test_memory_allocations_04.html (1812B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Bug 1068171 - Test controlling the memory actor's allocation sampling probability. 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 function allocator() { 27 for (let i = 0; i < 100; i++) { 28 allocs.push({}); 29 } 30 } 31 32 const testProbability = async function(p) { 33 info("probability = " + p); 34 await memory.startRecordingAllocations({ 35 probability: p, 36 }); 37 allocator(); 38 const response = await memory.getAllocations(); 39 await memory.stopRecordingAllocations(); 40 return response.allocations.length; 41 }; 42 43 is((await testProbability(0.0)), 0, 44 "With probability = 0.0, we shouldn't get any allocations."); 45 46 ok((await testProbability(1.0)) >= 100, 47 "With probability = 1.0, we should get all 100 allocations (plus " 48 + "whatever allocations the actor and SpiderMonkey make)."); 49 50 // We don't test any other probabilities because the test would be 51 // non-deterministic. We don't have a way to control the PRNG like we do in 52 // jit-tests 53 // (js/src/jit-test/tests/debug/Memory-allocationsSamplingProbability-*.js). 54 55 await memory.detach(); 56 destroyServerAndFinish(target); 57 })(); 58 }; 59 </script> 60 </pre> 61 </body> 62 </html>