test_HeapSnapshot_takeCensus_10.js (2068B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Check byte counts produced by takeCensus. 6 // 7 // Note that tracking allocation sites adds unique IDs to objects which 8 // increases their size, making it hard to test reported sizes exactly. 9 // 10 // Ported from js/src/jit-test/tests/debug/Memory-take Census-10.js 11 12 function run_test() { 13 const g = newGlobal(); 14 const dbg = new Debugger(g); 15 16 const sizeOfAM = byteSize(allocationMarker()); 17 18 // Allocate a single allocation marker, and check that we can find it. 19 g.eval("var hold = allocationMarker();"); 20 let census = saveHeapSnapshotAndTakeCensus(dbg, { 21 breakdown: { by: "objectClass" }, 22 }); 23 equal(census.AllocationMarker.count, 1); 24 equal(census.AllocationMarker.bytes >= sizeOfAM, true); 25 g.hold = null; 26 27 g.eval(` // 1 28 var objs = []; // 2 29 function fnerd() { // 3 30 objs.push(allocationMarker()); // 4 31 for (let i = 0; i < 10; i++) // 5 32 objs.push(allocationMarker()); // 6 33 } // 7 34 `); 35 36 dbg.memory.allocationSamplingProbability = 1; 37 dbg.memory.trackingAllocationSites = true; 38 g.fnerd(); 39 dbg.memory.trackingAllocationSites = false; 40 41 census = saveHeapSnapshotAndTakeCensus(dbg, { 42 breakdown: { by: "objectClass", then: { by: "allocationStack" } }, 43 }); 44 45 let seen = 0; 46 census.AllocationMarker.forEach((v, k) => { 47 equal(k.functionDisplayName, "fnerd"); 48 switch (k.line) { 49 case 4: 50 equal(v.count, 1); 51 equal(v.bytes >= sizeOfAM, true); 52 seen++; 53 break; 54 55 case 6: 56 equal(v.count, 10); 57 equal(v.bytes >= 10 * sizeOfAM, true); 58 seen++; 59 break; 60 61 default: 62 dumpn("Unexpected stack:"); 63 k.toString() 64 .split(/\n/g) 65 .forEach(s => dumpn(s)); 66 ok(false); 67 break; 68 } 69 }); 70 71 equal(seen, 2); 72 73 do_test_finished(); 74 }