Memory-allocationSamplingProbability-02.js (982B)
1 // Test that we only sample about allocationSamplingProbability * 100 percent of 2 // allocations. 3 4 const root = newGlobal({newCompartment: true}); 5 6 const dbg = new Debugger(); 7 const wrappedRoot = dbg.addDebuggee(root); 8 9 root.eval(` 10 objs = []; 11 objs.push(new Object); 12 `); 13 14 root.eval("" + function makeSomeAllocations() { 15 for (var i = 0; i < 100; i++) { 16 objs.push(new Object); 17 } 18 }); 19 20 function measure(P, expected) { 21 root.setSavedStacksRNGState(Number.MAX_SAFE_INTEGER - 1); 22 dbg.memory.allocationSamplingProbability = P; 23 root.makeSomeAllocations(); 24 assertEq(dbg.memory.drainAllocationsLog().length, expected); 25 } 26 27 dbg.memory.trackingAllocationSites = true; 28 29 // These are the sample counts that were correct when this test was last 30 // updated; changes to SpiderMonkey may occasionally cause changes 31 // here. Anything that is within a plausible range for the given sampling 32 // probability is fine. 33 measure(0.0, 0); 34 measure(1.0, 100); 35 measure(0.1, 11); 36 measure(0.5, 49);