| 1 |
// Test that drainAllocationsLog returns some timestamps. |
| 2 |
|
| 3 |
load(libdir + 'asserts.js'); |
| 4 |
|
| 5 |
var allocTimes = []; |
| 6 |
|
| 7 |
allocTimes.push(timeSinceCreation()); |
| 8 |
|
| 9 |
const root = newGlobal({newCompartment: true}); |
| 10 |
const dbg = new Debugger(root); |
| 11 |
|
| 12 |
dbg.memory.trackingAllocationSites = true; |
| 13 |
root.eval("this.alloc1 = {}"); |
| 14 |
allocTimes.push(timeSinceCreation()); |
| 15 |
root.eval("this.alloc2 = {}"); |
| 16 |
allocTimes.push(timeSinceCreation()); |
| 17 |
root.eval("this.alloc3 = {}"); |
| 18 |
allocTimes.push(timeSinceCreation()); |
| 19 |
root.eval("this.alloc4 = {}"); |
| 20 |
allocTimes.push(timeSinceCreation()); |
| 21 |
|
| 22 |
allocs = dbg.memory.drainAllocationsLog(); |
| 23 |
assertEq(allocs.length >= 4, true); |
| 24 |
assertEq(allocs[0].timestamp >= allocTimes[0], true); |
| 25 |
var seenAlloc = 0; |
| 26 |
var lastIndexSeenAllocIncremented = 0; |
| 27 |
for (i = 1; i < allocs.length; ++i) { |
| 28 |
assertEq(allocs[i].timestamp >= allocs[i - 1].timestamp, true); |
| 29 |
// It isn't possible to exactly correlate the entries in the |
| 30 |
// allocs array with the entries in allocTimes, because we can't |
| 31 |
// control exactly how many allocations are done during the course |
| 32 |
// of a given eval. However, we can assume that there is some |
| 33 |
// allocation recorded after each entry in allocTimes. So, we |
| 34 |
// track the allocTimes entry we've passed, and then after the |
| 35 |
// loop assert that we've seen them all. We also assert that a |
| 36 |
// non-zero number of allocations has happened since the last seen |
| 37 |
// increment. |
| 38 |
while (seenAlloc < allocTimes.length |
| 39 |
&& allocs[i].timestamp >= allocTimes[seenAlloc]) { |
| 40 |
assertEq(i - lastIndexSeenAllocIncremented > 0, true); |
| 41 |
lastIndexSeenAllocIncremented = i; |
| 42 |
++seenAlloc; |
| 43 |
} |
| 44 |
} |
| 45 |
// There should be one entry left in allocTimes, because we recorded a |
| 46 |
// time after the last possible allocation in the array. |
| 47 |
assertEq(seenAlloc, allocTimes.length -1); |