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

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

Issue 2999753002: Collate stacks in test output (Closed)
Patch Set: Created 3 years, 4 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
OLDNEW
(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 // $ dart stacks.dart LOG > STACK.txt
Siggi Cherem (dart-lang) 2017/08/09 18:09:06 consider renaming to include a verb that indicates
sra1 2017/08/09 20:15:13 Done.
6
7 import 'dart:io';
8
9 import 'log_parser.dart';
10
11 const STACK_PRINT_LENGTH = 12;
12 const HOW_MANY_STACKS = 30;
13
14 main(args) {
15 String text;
16
17 for (String arg in args) {
18 // Parse options.
19
20 if (text == null) {
21 var uri = Uri.base.resolve(arg);
22 var file = new File.fromUri(uri);
23 if (!file.existsSync()) {
24 print('file not found: $file');
25 exit(1);
26 }
27 text = file.readAsStringSync();
28 } else {
29 print('Extra file argument "$arg"');
30 exit(1);
31 }
32 }
33
34 if (text == null) {
35 print('No input file');
36 exit(1);
37 }
38
39 var records = parse(text);
40 var trie = new TrieNode(null);
41 for (var record in records) {
42 enter(record, 0, trie);
43 }
44
45 var leaves = trieLeaves(trie).toList();
46 leaves.sort((a, b) => b.length.compareTo(a.length));
47 for (var leaf in leaves.take(HOW_MANY_STACKS)) {
48 print('');
49 var examples = leaf.members.map((r) => r.fullReason).toSet();
50 print('${leaf.length} of:');
51 for (var example in examples) {
52 example = '\t' + example.replaceAll('\n', '\n\t');
53 print(' .${example}');
54 }
55
56 for (var line in leaf.members.first.stack.take(STACK_PRINT_LENGTH)) {
57 print(' $line');
58 }
59 }
60 }
61
62 class TrieNode {
63 final int depth;
64 final String key;
65 final map = {};
Siggi Cherem (dart-lang) 2017/08/09 18:08:02 Map<String, TrieNode> ?
sra1 2017/08/09 20:15:13 Done.
66 final List<Record> members = <Record>[];
67
68 int get length => members.length;
69
70 TrieNode(this.key, [this.depth = 0]);
71
72 String toString() => 'TrieNode(#$length)';
73 }
74
75 void enter(Record record, int depth, TrieNode root) {
76 root.members.add(record);
77 if (depth >= record.stack.length) return;
78 var key = record.stack[depth];
79 var node = root.map[key] ??= new TrieNode(key, depth + 1);
80 enter(record, depth + 1, node);
81 }
82
83 void printTrie(TrieNode node) {
84 var indent = ' ' * node.depth;
85 print('${indent} ${node.length} ${node.key}');
86 for (var key in node.map.keys) {
87 printTrie(node.map[key]);
88 }
89 }
90
91 trieLeaves(node) sync* {
92 if (node.map.isEmpty) {
93 yield node;
94 } else {
95 for (var v in node.map.values) {
96 yield* trieLeaves(v);
97 }
98 }
99 }
OLDNEW
« pkg/compiler/tool/status_files/log_parser.dart ('K') | « pkg/compiler/tool/status_files/record.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698