OLD | NEW |
---|---|
1 library compiler.tool.util; | 1 // Copyright (c) 2015, 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 library dart2js_info.src.util; | |
2 | 6 |
3 import 'package:dart2js_info/info.dart'; | 7 import 'package:dart2js_info/info.dart'; |
4 import 'graph.dart'; | 8 import 'graph.dart'; |
5 | 9 |
6 /// Computes a graph of dependencies from [info]. | 10 /// Computes a graph of dependencies from [info]. |
7 Graph<Info> graphFromInfo(AllInfo info) { | 11 Graph<Info> graphFromInfo(AllInfo info) { |
8 print(' info: dependency graph information is work in progress and' | 12 print(' info: dependency graph information is work in progress and' |
9 ' might be incomplete'); | 13 ' might be incomplete'); |
10 // Note: we are combining dependency information that is computed in two ways | 14 // Note: we are combining dependency information that is computed in two ways |
11 // (functionInfo.uses vs allInfo.dependencies). | 15 // (functionInfo.uses vs allInfo.dependencies). |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 return sb.toString(); | 70 return sb.toString(); |
67 } | 71 } |
68 | 72 |
69 /// Produce a string containing [value] padded with white space up to [n] chars. | 73 /// Produce a string containing [value] padded with white space up to [n] chars. |
70 pad(value, n, {bool right: false}) { | 74 pad(value, n, {bool right: false}) { |
71 var s = '$value'; | 75 var s = '$value'; |
72 if (s.length >= n) return s; | 76 if (s.length >= n) return s; |
73 var pad = ' ' * (n - s.length); | 77 var pad = ' ' * (n - s.length); |
74 return right ? '$s$pad' : '$pad$s'; | 78 return right ? '$s$pad' : '$pad$s'; |
75 } | 79 } |
80 | |
81 /// Color-highighted string used mainly to debug invariants. | |
Johnni Winther
2015/10/02 10:09:49
highighted -> highlighted
Siggi Cherem (dart-lang)
2015/10/02 17:16:17
Done.
| |
82 String recursiveDiagnosticString(Measurements measurements, Metric metric) { | |
83 var sb = new StringBuffer(); | |
84 helper(Metric m) { | |
85 int value = measurements.counters[m]; | |
86 if (value == null) value = 0; | |
87 if (m is! GroupedMetric) { | |
88 sb.write(value); | |
89 sb.write(' ${m.name}'); | |
90 return; | |
91 } | |
92 GroupedMetric group = m; | |
93 | |
94 int expected = 0; | |
95 for (var sub in group.submetrics) { | |
96 var n = measurements.counters[sub]; | |
97 if (n != null) expected += n; | |
98 } | |
99 if (value == expected) { | |
100 sb.write('[32m'); | |
101 sb.write(value); | |
102 } else { | |
103 sb.write('[31m'); | |
104 sb.write(value); | |
105 sb.write('[33m['); | |
106 sb.write(expected); | |
107 sb.write(']'); | |
Johnni Winther
2015/10/02 10:09:49
indentation
Siggi Cherem (dart-lang)
2015/10/02 17:16:17
Done.
| |
108 } | |
109 sb.write('[0m'); | |
110 sb.write(' ${group.name}'); | |
111 | |
112 bool first = true; | |
113 sb.write('('); | |
114 for (var sub in group.submetrics) { | |
115 if (first) { | |
116 first = false; | |
117 } else { | |
118 sb.write(' + '); | |
119 } | |
120 helper(sub); | |
121 } | |
122 sb.write(')'); | |
123 } | |
124 helper(metric); | |
125 return sb.toString(); | |
126 } | |
OLD | NEW |