Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: pkg/compiler/tool/status_files/rank_stacks.dart

Issue 3007023002: rank_stacks tweaks (Closed)
Patch Set: Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 \
(...skipping 19 matching lines...) Expand all
30 print(why); 30 print(why);
31 print('Usage:\n' 31 print('Usage:\n'
32 'dart rank_stacks.dart [options] test-logs\n\n' 32 'dart rank_stacks.dart [options] test-logs\n\n'
33 '${argParser.usage}'); 33 '${argParser.usage}');
34 exit(1); 34 exit(1);
35 } 35 }
36 36
37 ArgParser argParser = new ArgParser() 37 ArgParser argParser = new ArgParser()
38 ..addOption('stacks', 38 ..addOption('stacks',
39 abbr: 's', 39 abbr: 's',
40 defaultsTo: '30', 40 defaultsTo: '0',
41 help: 'Number of highest ranking stacks to print.') 41 help: 'Number of highest ranking stacks to print (0 for all).')
42 ..addOption('length', 42 ..addOption('length',
43 abbr: 'l', defaultsTo: '12', help: 'Number of stack frames printed.'); 43 abbr: 'l', defaultsTo: '12', help: 'Number of stack frames printed.');
44 44
45 int intOption(ArgResults args, String name) { 45 int intOption(ArgResults args, String name) {
46 onError(String text) { 46 onError(String text) {
47 die("Value '$text' is not an integer. " 47 die("Value '$text' is not an integer. "
48 "Option '$name' requires an integer value."); 48 "Option '$name' requires an integer value.");
49 } 49 }
50 50
51 return int.parse(args[name], onError: onError); 51 return int.parse(args[name], onError: onError);
(...skipping 15 matching lines...) Expand all
67 for (String input in rest) { 67 for (String input in rest) {
68 var uri = Uri.base.resolve(input); 68 var uri = Uri.base.resolve(input);
69 var file = new File.fromUri(uri); 69 var file = new File.fromUri(uri);
70 if (!file.existsSync()) { 70 if (!file.existsSync()) {
71 die("File not found: '$input'."); 71 die("File not found: '$input'.");
72 } 72 }
73 String text = file.readAsStringSync(); 73 String text = file.readAsStringSync();
74 records.addAll(parse(text)); 74 records.addAll(parse(text));
75 } 75 }
76 76
77 var trie = new TrieNode(null); 77 var trie = new TrieNode(null, 0);
78 for (var record in records) { 78 for (var record in records) {
79 enter(record, 0, trie); 79 enter(record, 0, trie);
80 } 80 }
81 81
82 var leaves = trieLeaves(trie).toList(); 82 var leaves = trieLeaves(trie).toList();
83 leaves.sort(compareNodesByCountAndStack); 83 leaves.sort(compareNodesByCountAndStack);
84 for (var leaf in howManyStacks == 0 ? leaves : leaves.take(howManyStacks)) { 84 for (var leaf in howManyStacks == 0 ? leaves : leaves.take(howManyStacks)) {
85 print(''); 85 print('');
86 var examples = leaf.members.map((r) => r.fullReason).toSet().toList(); 86 var examples = leaf.members.map(fullReasonOf).toSet().toList();
87 examples.sort(); 87 examples.sort();
88 print('${leaf.length} of:'); 88 print('${leaf.length} of:');
89 for (var example in examples) { 89 for (var example in examples) {
90 var count = leaf.members.where((r) => r.fullReason == example).length; 90 var count = leaf.members.where((r) => fullReasonOf(r) == example).length;
91 var countAligned = '$count'.padLeft(6); 91 var countAligned = '$count'.padLeft(6);
92 if (examples.length == 1) countAligned = ' .'; 92 if (examples.length == 1) countAligned = ' .';
93 var indentedExample = '\t' + example.replaceAll('\n', '\n\t'); 93 var indentedExample = '\t' + example.replaceAll('\n', '\n\t');
94 print('${countAligned}${indentedExample}'); 94 print('${countAligned}${indentedExample}');
95 } 95 }
96 96
97 for (var line in leaf.members.first.stack.take(stackPrintLength)) { 97 for (var line in leaf.members.first.stack.take(stackPrintLength)) {
98 print(' $line'); 98 print(' $line');
99 } 99 }
100 } 100 }
101 } 101 }
102 102
103 String fullReasonOf(Record r) {
104 // Some records have no matched reason, so default to test status.
105 return r.fullReason ?? r.actual;
106 }
107
103 int compareNodesByCountAndStack(TrieNode a, TrieNode b) { 108 int compareNodesByCountAndStack(TrieNode a, TrieNode b) {
104 int r = b.length.compareTo(a.length); 109 int r = b.length.compareTo(a.length);
105 if (r != 0) return r; 110 if (r != 0) return r;
106 List<String> stackA = a.members.first.stack; 111 List<String> stackA = a.members.first.stack;
107 List<String> stackB = b.members.first.stack; 112 List<String> stackB = b.members.first.stack;
108 int lengthA = stackA.length; 113 int lengthA = stackA.length;
109 int lengthB = stackB.length; 114 int lengthB = stackB.length;
110 for (int i = 0; i < lengthA && i < lengthB; i++) { 115 for (int i = 0; i < lengthA && i < lengthB; i++) {
111 r = stackA[i].compareTo(stackB[i]); 116 r = stackA[i].compareTo(stackB[i]);
112 if (r != 0) return r; 117 if (r != 0) return r;
113 } 118 }
114 return lengthA.compareTo(lengthB); 119 return lengthA.compareTo(lengthB);
115 } 120 }
116 121
117 class TrieNode { 122 class TrieNode {
118 final int depth; 123 final int depth;
119 final String key; 124 final String key;
120 final Map<String, TrieNode> map = <String, TrieNode>{}; 125 final Map<String, TrieNode> map = <String, TrieNode>{};
121 final List<Record> members = <Record>[]; 126 final List<Record> members = <Record>[];
122 127
123 int get length => members.length; 128 int get length => members.length;
124 129
125 TrieNode(this.key, [this.depth = 0]); 130 TrieNode(this.key, this.depth);
126 131
127 String toString() => 'TrieNode(#$length)'; 132 String toString() => 'TrieNode(#$length)';
128 } 133 }
129 134
130 void enter(Record record, int depth, TrieNode root) { 135 void enter(Record record, int depth, TrieNode root) {
131 root.members.add(record); 136 // Cluster on printed stack.
132 if (depth >= record.stack.length) return; 137 if (depth >= stackPrintLength || depth >= record.stack.length) {
138 root.members.add(record);
139 return;
140 }
133 var key = record.stack[depth]; 141 var key = record.stack[depth];
134 var node = root.map[key] ??= new TrieNode(key, depth + 1); 142 var node = root.map[key] ??= new TrieNode(key, depth + 1);
135 enter(record, depth + 1, node); 143 enter(record, depth + 1, node);
136 } 144 }
137 145
138 void printTrie(TrieNode node) { 146 void printTrie(TrieNode node) {
139 var indent = ' ' * node.depth; 147 var indent = ' ' * node.depth;
140 print('${indent} ${node.length} ${node.key}'); 148 print('${indent} ${node.length} ${node.key}');
141 for (var key in node.map.keys) { 149 for (var key in node.map.keys) {
142 printTrie(node.map[key]); 150 printTrie(node.map[key]);
143 } 151 }
144 } 152 }
145 153
146 trieLeaves(node) sync* { 154 trieLeaves(node) sync* {
147 if (node.map.isEmpty) { 155 if (node.members.isNotEmpty) {
148 yield node; 156 yield node;
149 } else { 157 }
150 for (var v in node.map.values) { 158 for (var v in node.map.values) {
151 yield* trieLeaves(v); 159 yield* trieLeaves(v);
152 }
153 } 160 }
154 } 161 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698