Memory-takeCensus-10.js (1570B)
1 // Check counts produced by takeCensus. 2 // 3 // Note that tracking allocation sites adds unique IDs to objects which 4 // increases their size, making it hard to test reported sizes exactly. 5 6 let g = newGlobal({newCompartment: true}); 7 let dbg = new Debugger(g); 8 9 let sizeOfAM = byteSize(allocationMarker()); 10 11 // Allocate a single allocation marker, and check that we can find it. 12 g.eval('var hold = allocationMarker();'); 13 let census = dbg.memory.takeCensus({ breakdown: { by: 'objectClass' } }); 14 assertEq(census.AllocationMarker.count, 1); 15 assertEq(census.AllocationMarker.bytes, sizeOfAM); 16 17 g.evaluate(` 18 var objs = []; 19 function fnerd() { 20 objs.push(allocationMarker()); 21 for (let i = 0; i < 10; i++) 22 objs.push(allocationMarker()); 23 } 24 `, 25 { fileName: 'J. Edgar Hoover', lineNumber: 2000 }); 26 27 dbg.memory.allocationSamplingProbability = 1; 28 dbg.memory.trackingAllocationSites = true; 29 30 g.hold = null; 31 g.fnerd(); 32 33 census = dbg.memory.takeCensus({ 34 breakdown: { by: 'objectClass', 35 then: { by: 'allocationStack' } 36 } 37 }); 38 39 let seen = 0; 40 census.AllocationMarker.forEach((v, k) => { 41 assertEq(k.functionDisplayName, 'fnerd'); 42 assertEq(k.source, 'J. Edgar Hoover'); 43 switch (k.line) { 44 case 2003: 45 assertEq(v.count, 1); 46 assertEq(v.bytes >= sizeOfAM, true); 47 seen++; 48 break; 49 50 case 2005: 51 assertEq(v.count, 10); 52 assertEq(v.bytes >= 10 * sizeOfAM, true); 53 seen++; 54 break; 55 56 default: assertEq(true, false); 57 } 58 }); 59 60 assertEq(seen, 2);