computeGCFunctions.js (3011B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */ 6 "use strict"; 7 8 loadRelativeToScript('utility.js'); 9 loadRelativeToScript('annotations.js'); 10 loadRelativeToScript('loadCallgraph.js'); 11 12 function usage() { 13 throw "Usage: computeGCFunctions.js <rawcalls1.txt> <rawcalls2.txt>... --outputs <out:callgraph.txt> <out:gcFunctions.txt> <out:gcFunctions.lst> <out:gcEdges.txt> <out:limitedFunctions.lst>"; 14 } 15 16 if (typeof scriptArgs[0] != 'string') 17 usage(); 18 19 var start = "Time: " + new Date; 20 21 try { 22 var options = parse_options([ 23 { 24 name: '--verbose', 25 type: 'bool' 26 }, 27 { 28 name: 'inputs', 29 dest: 'rawcalls_filenames', 30 nargs: '+' 31 }, 32 { 33 name: '--outputs', 34 type: 'bool' 35 }, 36 { 37 name: 'callgraph', 38 type: 'string', 39 default: 'callgraph.txt' 40 }, 41 { 42 name: 'gcFunctions', 43 type: 'string', 44 default: 'gcFunctions.txt' 45 }, 46 { 47 name: 'gcFunctionsList', 48 type: 'string', 49 default: 'gcFunctions.lst' 50 }, 51 { 52 name: 'limitedFunctions', 53 type: 'string', 54 default: 'limitedFunctions.lst' 55 }, 56 ]); 57 } catch { 58 printErr("Usage: computeGCFunctions.js [--verbose] <rawcalls1.txt> <rawcalls2.txt>... --outputs <out:callgraph.txt> <out:gcFunctions.txt> <out:gcFunctions.lst> <out:gcEdges.txt> <out:limitedFunctions.lst>"); 59 quit(1); 60 }; 61 62 function info(message) { 63 if (options.verbose) { 64 printErr(message); 65 } 66 } 67 68 var { 69 gcFunctions, 70 functions, 71 calleesOf, 72 limitedFunctions 73 } = loadCallgraph(options.rawcalls_filenames, options.verbose); 74 75 info("Writing " + options.gcFunctions); 76 redirect(options.gcFunctions); 77 78 for (var name in gcFunctions) { 79 for (let readable of (functions.readableName[name] || [name])) { 80 print(""); 81 const fullname = (name == readable) ? name : name + "$" + readable; 82 print("GC Function: " + fullname); 83 let current = name; 84 do { 85 current = gcFunctions[current]; 86 if (current === 'internal') 87 ; // Hit the end 88 else if (current in functions.readableName) 89 print(" " + functions.readableName[current][0]); 90 else 91 print(" " + current); 92 } while (current in gcFunctions); 93 } 94 } 95 96 info("Writing " + options.gcFunctionsList); 97 redirect(options.gcFunctionsList); 98 for (var name in gcFunctions) { 99 if (name in functions.readableName) { 100 for (var readable of functions.readableName[name]) 101 print(name + "$" + readable); 102 } else { 103 print(name); 104 } 105 } 106 107 info("Writing " + options.limitedFunctions); 108 redirect(options.limitedFunctions); 109 print(JSON.stringify(limitedFunctions, null, 4)); 110 111 info("Writing " + options.callgraph); 112 redirect(options.callgraph); 113 saveCallgraph(functions, calleesOf);