| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /* |
| 6 Usage: |
| 7 |
| 8 $ tools/test.py -m release \ |
| 9 -c dart2js -r d8 --dart2js-batch --report \ |
| 10 --host-checked \ |
| 11 --dart2js_options="--library-root=out/ReleaseX64/dart-sdk/ --use-kernel" \ |
| 12 language corelib library_2 corelib_2 \ |
| 13 dart2js_native dart2js_extra \ |
| 14 2>&1 > LOG |
| 15 |
| 16 $ sdk/bin/dart pkg/compiler/tool/status_files/rank_stacks.dart LOG > STACKS.tx
t |
| 17 */ |
| 18 |
| 19 import 'dart:io'; |
| 20 |
| 21 import 'log_parser.dart'; |
| 22 import 'record.dart'; |
| 23 |
| 24 // TODO(sra): Allow command-line setting of these parameters. |
| 25 const STACK_PRINT_LENGTH = 12; |
| 26 const HOW_MANY_STACKS = 30; |
| 27 |
| 28 main(args) { |
| 29 String text; |
| 30 |
| 31 for (String arg in args) { |
| 32 // Parse options. |
| 33 |
| 34 if (text == null) { |
| 35 var uri = Uri.base.resolve(arg); |
| 36 var file = new File.fromUri(uri); |
| 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 } |
| 47 |
| 48 if (text == null) { |
| 49 print('No input file.'); |
| 50 exit(1); |
| 51 } |
| 52 |
| 53 var records = parse(text); |
| 54 var trie = new TrieNode(null); |
| 55 for (var record in records) { |
| 56 enter(record, 0, trie); |
| 57 } |
| 58 |
| 59 var leaves = trieLeaves(trie).toList(); |
| 60 leaves.sort((a, b) => b.length.compareTo(a.length)); |
| 61 for (var leaf in leaves.take(HOW_MANY_STACKS)) { |
| 62 print(''); |
| 63 var examples = leaf.members.map((r) => r.fullReason).toSet().toList(); |
| 64 examples.sort(); |
| 65 print('${leaf.length} of:'); |
| 66 for (var example in examples) { |
| 67 var count = leaf.members.where((r) => r.fullReason == example).length; |
| 68 var countAligned = '$count'.padLeft(6); |
| 69 if (examples.length == 1) countAligned = ' .'; |
| 70 var indentedExample = '\t' + example.replaceAll('\n', '\n\t'); |
| 71 print('${countAligned}${indentedExample}'); |
| 72 } |
| 73 |
| 74 for (var line in leaf.members.first.stack.take(STACK_PRINT_LENGTH)) { |
| 75 print(' $line'); |
| 76 } |
| 77 } |
| 78 } |
| 79 |
| 80 class TrieNode { |
| 81 final int depth; |
| 82 final String key; |
| 83 final Map<String, TrieNode> map = <String, TrieNode>{}; |
| 84 final List<Record> members = <Record>[]; |
| 85 |
| 86 int get length => members.length; |
| 87 |
| 88 TrieNode(this.key, [this.depth = 0]); |
| 89 |
| 90 String toString() => 'TrieNode(#$length)'; |
| 91 } |
| 92 |
| 93 void enter(Record record, int depth, TrieNode root) { |
| 94 root.members.add(record); |
| 95 if (depth >= record.stack.length) return; |
| 96 var key = record.stack[depth]; |
| 97 var node = root.map[key] ??= new TrieNode(key, depth + 1); |
| 98 enter(record, depth + 1, node); |
| 99 } |
| 100 |
| 101 void printTrie(TrieNode node) { |
| 102 var indent = ' ' * node.depth; |
| 103 print('${indent} ${node.length} ${node.key}'); |
| 104 for (var key in node.map.keys) { |
| 105 printTrie(node.map[key]); |
| 106 } |
| 107 } |
| 108 |
| 109 trieLeaves(node) sync* { |
| 110 if (node.map.isEmpty) { |
| 111 yield node; |
| 112 } else { |
| 113 for (var v in node.map.values) { |
| 114 yield* trieLeaves(v); |
| 115 } |
| 116 } |
| 117 } |
| OLD | NEW |