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

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

Issue 3005683002: Add command line options to rank_stacks (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 \
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 'log_parser.dart'; 21 import 'log_parser.dart';
22 import 'record.dart'; 22 import 'record.dart';
23 23
24 // TODO(sra): Allow command-line setting of these parameters. 24 const DEFAULT_STACK_PRINT_LENGTH = 12;
25 const STACK_PRINT_LENGTH = 12; 25 const DEFAULT_HOW_MANY_STACKS = 20;
26 const HOW_MANY_STACKS = 30; 26 const USAGE = """
27 dart rank_stacks.dart [options] test-log
28
29 --stacks=N, -sN: Print highest ranking N stacks (0 means all stacks).
30 Defaults to top ${DEFAULT_HOW_MANY_STACKS} stacks.
31
32 --length=N, -lN: Print N frames of each stack.
33 Defaults to ${DEFAULT_STACK_PRINT_LENGTH} frames.
34 """;
35
36 int stackPrintLength = DEFAULT_STACK_PRINT_LENGTH;
37 int howManyStacks = DEFAULT_HOW_MANY_STACKS;
38
39 void die(String why) {
40 print(why);
41 print('Usage:\n${USAGE}');
42 exit(1);
43 }
27 44
28 main(args) { 45 main(args) {
29 String text; 46 String text;
30 47
48 // Parse options.
31 for (String arg in args) { 49 for (String arg in args) {
32 // Parse options. 50 Match m;
51 if ((m = new RegExp(r'(--stacks=|-s)(\d+)$').matchAsPrefix(arg)) != null) {
Siggi Cherem (dart-lang) 2017/08/26 02:09:00 consider using the `args` package?
sra1 2017/08/29 19:53:03 Done.
52 howManyStacks = int.parse(m.group(2));
53 continue;
54 }
55
56 if ((m = new RegExp(r'(--length=|-l)(\d+)$').matchAsPrefix(arg)) != null) {
57 stackPrintLength = int.parse(m.group(2));
58 continue;
59 }
60
61 if (arg.startsWith('-')) die("Unknown option '$arg'");
33 62
34 if (text == null) { 63 if (text == null) {
35 var uri = Uri.base.resolve(arg); 64 var uri = Uri.base.resolve(arg);
36 var file = new File.fromUri(uri); 65 var file = new File.fromUri(uri);
37 if (!file.existsSync()) { 66 if (!file.existsSync()) {
38 print('File not found: $file.'); 67 die('File not found: $file.');
39 exit(1);
40 } 68 }
41 text = file.readAsStringSync(); 69 text = file.readAsStringSync();
42 } else { 70 } else {
43 print("Extra file argument '$arg'."); 71 die("Extra file argument '$arg'.");
44 exit(1);
45 } 72 }
46 } 73 }
47 74
48 if (text == null) { 75 if (text == null) {
49 print('No input file.'); 76 die('No input file.');
50 exit(1);
51 } 77 }
52 78
53 var records = parse(text); 79 var records = parse(text);
54 var trie = new TrieNode(null); 80 var trie = new TrieNode(null);
55 for (var record in records) { 81 for (var record in records) {
56 enter(record, 0, trie); 82 enter(record, 0, trie);
57 } 83 }
58 84
59 var leaves = trieLeaves(trie).toList(); 85 var leaves = trieLeaves(trie).toList();
60 leaves.sort((a, b) => b.length.compareTo(a.length)); 86 leaves.sort((a, b) => b.length.compareTo(a.length));
61 for (var leaf in leaves.take(HOW_MANY_STACKS)) { 87 for (var leaf in howManyStacks == 0 ? leaves : leaves.take(howManyStacks)) {
62 print(''); 88 print('');
63 var examples = leaf.members.map((r) => r.fullReason).toSet().toList(); 89 var examples = leaf.members.map((r) => r.fullReason).toSet().toList();
64 examples.sort(); 90 examples.sort();
65 print('${leaf.length} of:'); 91 print('${leaf.length} of:');
66 for (var example in examples) { 92 for (var example in examples) {
67 var count = leaf.members.where((r) => r.fullReason == example).length; 93 var count = leaf.members.where((r) => r.fullReason == example).length;
68 var countAligned = '$count'.padLeft(6); 94 var countAligned = '$count'.padLeft(6);
69 if (examples.length == 1) countAligned = ' .'; 95 if (examples.length == 1) countAligned = ' .';
70 var indentedExample = '\t' + example.replaceAll('\n', '\n\t'); 96 var indentedExample = '\t' + example.replaceAll('\n', '\n\t');
71 print('${countAligned}${indentedExample}'); 97 print('${countAligned}${indentedExample}');
72 } 98 }
73 99
74 for (var line in leaf.members.first.stack.take(STACK_PRINT_LENGTH)) { 100 for (var line in leaf.members.first.stack.take(stackPrintLength)) {
75 print(' $line'); 101 print(' $line');
76 } 102 }
77 } 103 }
78 } 104 }
79 105
80 class TrieNode { 106 class TrieNode {
81 final int depth; 107 final int depth;
82 final String key; 108 final String key;
83 final Map<String, TrieNode> map = <String, TrieNode>{}; 109 final Map<String, TrieNode> map = <String, TrieNode>{};
84 final List<Record> members = <Record>[]; 110 final List<Record> members = <Record>[];
(...skipping 23 matching lines...) Expand all
108 134
109 trieLeaves(node) sync* { 135 trieLeaves(node) sync* {
110 if (node.map.isEmpty) { 136 if (node.map.isEmpty) {
111 yield node; 137 yield node;
112 } else { 138 } else {
113 for (var v in node.map.values) { 139 for (var v in node.map.values) {
114 yield* trieLeaves(v); 140 yield* trieLeaves(v);
115 } 141 }
116 } 142 }
117 } 143 }
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