test_DominatorTree_06.js (2076B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test that the retained size of a node is the sum of its children retained 6 // sizes plus its shallow size. 7 8 // Note that we don't assert directly, only if we get an unexpected 9 // value. There are just way too many nodes in the heap graph to assert for 10 // every one. This test would constantly time out and assertion messages would 11 // overflow the log size. 12 function fastAssert(cond, msg) { 13 if (!cond) { 14 ok(false, msg); 15 } 16 } 17 18 const COUNT = { by: "count", count: false, bytes: true }; 19 20 function run_test() { 21 const path = saveNewHeapSnapshot(); 22 const snapshot = ChromeUtils.readHeapSnapshot(path); 23 const dominatorTree = snapshot.computeDominatorTree(); 24 25 // Do a traversal of the dominator tree and assert the relationship between 26 // retained size, shallow size, and children's retained sizes. 27 28 const root = dominatorTree.root; 29 const stack = [root]; 30 while (stack.length) { 31 const top = stack.pop(); 32 33 const children = dominatorTree.getImmediatelyDominated(top); 34 35 const topRetainedSize = dominatorTree.getRetainedSize(top); 36 const topShallowSize = snapshot.describeNode(COUNT, top).bytes; 37 fastAssert( 38 topShallowSize <= topRetainedSize, 39 "The shallow size should be less than or equal to the " + "retained size" 40 ); 41 42 let sumOfChildrensRetainedSizes = 0; 43 for (let i = 0; i < children.length; i++) { 44 sumOfChildrensRetainedSizes += dominatorTree.getRetainedSize(children[i]); 45 stack.push(children[i]); 46 } 47 48 fastAssert( 49 sumOfChildrensRetainedSizes <= topRetainedSize, 50 "The sum of the children's retained sizes should be less than " + 51 "or equal to the retained size" 52 ); 53 fastAssert( 54 sumOfChildrensRetainedSizes + topShallowSize === topRetainedSize, 55 "The sum of the children's retained sizes plus the shallow " + 56 "size should be equal to the retained size" 57 ); 58 } 59 60 ok(true, "Successfully walked the tree"); 61 do_test_finished(); 62 }