| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /* | 5 /* |
| 6 Usage: | 6 Usage: |
| 7 | 7 |
| 8 $ tools/test.py -m release \ | 8 $ tools/test.py -m release \ |
| 9 -c dart2js -r d8 --dart2js-batch --report \ | 9 -c dart2js -r d8 --dart2js-batch --report \ |
| 10 --host-checked \ | 10 --host-checked \ |
| 11 --dart2js_options="--library-root=out/ReleaseX64/dart-sdk/ --use-kernel" \ | 11 --dart2js_options="--library-root=out/ReleaseX64/dart-sdk/ --use-kernel" \ |
| 12 language corelib library_2 corelib_2 \ | 12 language corelib library_2 corelib_2 \ |
| 13 dart2js_native dart2js_extra \ | 13 dart2js_native dart2js_extra \ |
| 14 2>&1 > LOG | 14 2>&1 > LOG |
| 15 | 15 |
| 16 $ sdk/bin/dart pkg/compiler/tool/status_files/rank_stacks.dart LOG > STACKS.tx
t | 16 $ sdk/bin/dart pkg/compiler/tool/status_files/rank_stacks.dart LOG > STACKS.tx
t |
| 17 */ | 17 */ |
| 18 | 18 |
| 19 import 'dart:io'; | 19 import 'dart:io'; |
| 20 | 20 |
| 21 import 'package:args/args.dart'; |
| 22 |
| 21 import 'log_parser.dart'; | 23 import 'log_parser.dart'; |
| 22 import 'record.dart'; | 24 import 'record.dart'; |
| 23 | 25 |
| 24 // TODO(sra): Allow command-line setting of these parameters. | 26 int stackPrintLength; |
| 25 const STACK_PRINT_LENGTH = 12; | 27 int howManyStacks; |
| 26 const HOW_MANY_STACKS = 30; | 28 |
| 29 void die(String why) { |
| 30 print(why); |
| 31 print('Usage:\n' |
| 32 'dart rank_stacks.dart [options] test-logs\n\n' |
| 33 '${argParser.usage}'); |
| 34 exit(1); |
| 35 } |
| 36 |
| 37 ArgParser argParser = new ArgParser() |
| 38 ..addOption('stacks', |
| 39 abbr: 's', |
| 40 defaultsTo: '30', |
| 41 help: 'Number of highest ranking stacks to print.') |
| 42 ..addOption('length', |
| 43 abbr: 'l', defaultsTo: '12', help: 'Number of stack frames printed.'); |
| 44 |
| 45 int intOption(ArgResults args, String name) { |
| 46 onError(String text) { |
| 47 die("Value '$text' is not an integer. " |
| 48 "Option '$name' requires an integer value."); |
| 49 } |
| 50 |
| 51 return int.parse(args[name], onError: onError); |
| 52 } |
| 27 | 53 |
| 28 main(args) { | 54 main(args) { |
| 29 String text; | 55 List<String> rest; |
| 30 | 56 try { |
| 31 for (String arg in args) { | 57 var argResults = argParser.parse(args); |
| 32 // Parse options. | 58 howManyStacks = intOption(argResults, 'stacks'); |
| 33 | 59 stackPrintLength = intOption(argResults, 'length'); |
| 34 if (text == null) { | 60 rest = argResults.rest; |
| 35 var uri = Uri.base.resolve(arg); | 61 } catch (e) { |
| 36 var file = new File.fromUri(uri); | 62 die('$e'); |
| 37 if (!file.existsSync()) { | |
| 38 print('File not found: $file.'); | |
| 39 exit(1); | |
| 40 } | |
| 41 text = file.readAsStringSync(); | |
| 42 } else { | |
| 43 print("Extra file argument '$arg'."); | |
| 44 exit(1); | |
| 45 } | |
| 46 } | 63 } |
| 47 | 64 |
| 48 if (text == null) { | 65 if (rest.isEmpty) die('No input file.'); |
| 49 print('No input file.'); | 66 var records = <Record>[]; |
| 50 exit(1); | 67 for (String input in rest) { |
| 68 var uri = Uri.base.resolve(input); |
| 69 var file = new File.fromUri(uri); |
| 70 if (!file.existsSync()) { |
| 71 die("File not found: '$input'."); |
| 72 } |
| 73 String text = file.readAsStringSync(); |
| 74 records.addAll(parse(text)); |
| 51 } | 75 } |
| 52 | 76 |
| 53 var records = parse(text); | |
| 54 var trie = new TrieNode(null); | 77 var trie = new TrieNode(null); |
| 55 for (var record in records) { | 78 for (var record in records) { |
| 56 enter(record, 0, trie); | 79 enter(record, 0, trie); |
| 57 } | 80 } |
| 58 | 81 |
| 59 var leaves = trieLeaves(trie).toList(); | 82 var leaves = trieLeaves(trie).toList(); |
| 60 leaves.sort((a, b) => b.length.compareTo(a.length)); | 83 leaves.sort(compareNodesByCountAndStack); |
| 61 for (var leaf in leaves.take(HOW_MANY_STACKS)) { | 84 for (var leaf in howManyStacks == 0 ? leaves : leaves.take(howManyStacks)) { |
| 62 print(''); | 85 print(''); |
| 63 var examples = leaf.members.map((r) => r.fullReason).toSet().toList(); | 86 var examples = leaf.members.map((r) => r.fullReason).toSet().toList(); |
| 64 examples.sort(); | 87 examples.sort(); |
| 65 print('${leaf.length} of:'); | 88 print('${leaf.length} of:'); |
| 66 for (var example in examples) { | 89 for (var example in examples) { |
| 67 var count = leaf.members.where((r) => r.fullReason == example).length; | 90 var count = leaf.members.where((r) => r.fullReason == example).length; |
| 68 var countAligned = '$count'.padLeft(6); | 91 var countAligned = '$count'.padLeft(6); |
| 69 if (examples.length == 1) countAligned = ' .'; | 92 if (examples.length == 1) countAligned = ' .'; |
| 70 var indentedExample = '\t' + example.replaceAll('\n', '\n\t'); | 93 var indentedExample = '\t' + example.replaceAll('\n', '\n\t'); |
| 71 print('${countAligned}${indentedExample}'); | 94 print('${countAligned}${indentedExample}'); |
| 72 } | 95 } |
| 73 | 96 |
| 74 for (var line in leaf.members.first.stack.take(STACK_PRINT_LENGTH)) { | 97 for (var line in leaf.members.first.stack.take(stackPrintLength)) { |
| 75 print(' $line'); | 98 print(' $line'); |
| 76 } | 99 } |
| 77 } | 100 } |
| 78 } | 101 } |
| 79 | 102 |
| 103 int compareNodesByCountAndStack(TrieNode a, TrieNode b) { |
| 104 int r = b.length.compareTo(a.length); |
| 105 if (r != 0) return r; |
| 106 List<String> stackA = a.members.first.stack; |
| 107 List<String> stackB = b.members.first.stack; |
| 108 int lengthA = stackA.length; |
| 109 int lengthB = stackB.length; |
| 110 for (int i = 0; i < lengthA && i < lengthB; i++) { |
| 111 r = stackA[i].compareTo(stackB[i]); |
| 112 if (r != 0) return r; |
| 113 } |
| 114 return lengthA.compareTo(lengthB); |
| 115 } |
| 116 |
| 80 class TrieNode { | 117 class TrieNode { |
| 81 final int depth; | 118 final int depth; |
| 82 final String key; | 119 final String key; |
| 83 final Map<String, TrieNode> map = <String, TrieNode>{}; | 120 final Map<String, TrieNode> map = <String, TrieNode>{}; |
| 84 final List<Record> members = <Record>[]; | 121 final List<Record> members = <Record>[]; |
| 85 | 122 |
| 86 int get length => members.length; | 123 int get length => members.length; |
| 87 | 124 |
| 88 TrieNode(this.key, [this.depth = 0]); | 125 TrieNode(this.key, [this.depth = 0]); |
| 89 | 126 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 108 | 145 |
| 109 trieLeaves(node) sync* { | 146 trieLeaves(node) sync* { |
| 110 if (node.map.isEmpty) { | 147 if (node.map.isEmpty) { |
| 111 yield node; | 148 yield node; |
| 112 } else { | 149 } else { |
| 113 for (var v in node.map.values) { | 150 for (var v in node.map.values) { |
| 114 yield* trieLeaves(v); | 151 yield* trieLeaves(v); |
| 115 } | 152 } |
| 116 } | 153 } |
| 117 } | 154 } |
| OLD | NEW |