OLD | NEW |
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 /// An entrypoint used to run portions of fasta and measure its performance. | 5 /// An entrypoint used to run portions of fasta and measure its performance. |
6 library front_end.tool.fasta_perf; | 6 library front_end.tool.fasta_perf; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
11 import 'package:analyzer/src/fasta/ast_builder.dart'; | 11 import 'package:analyzer/src/fasta/ast_builder.dart'; |
12 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; | 12 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; |
13 import 'package:front_end/src/fasta/kernel/kernel_target.dart' | 13 import 'package:front_end/src/fasta/kernel/kernel_target.dart' |
14 show KernelTarget; | 14 show KernelTarget; |
15 import 'package:front_end/src/fasta/parser.dart'; | 15 import 'package:front_end/src/fasta/parser.dart'; |
| 16 import 'package:front_end/src/fasta/source/directive_listener.dart'; |
16 import 'package:front_end/src/fasta/scanner.dart'; | 17 import 'package:front_end/src/fasta/scanner.dart'; |
17 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; | 18 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; |
18 import 'package:front_end/src/fasta/source/directive_listener.dart'; | |
19 import 'package:front_end/src/fasta/ticker.dart' show Ticker; | 19 import 'package:front_end/src/fasta/ticker.dart' show Ticker; |
20 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; | 20 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; |
21 import 'package:front_end/src/fasta/translate_uri.dart'; | 21 import 'package:front_end/src/fasta/translate_uri.dart'; |
22 import 'package:front_end/src/fasta/parser/dart_vm_native.dart' | |
23 show skipNativeClause; | |
24 | 22 |
25 /// Cumulative total number of chars scanned. | 23 /// Cumulative total number of chars scanned. |
26 int inputSize = 0; | 24 int inputSize = 0; |
27 | 25 |
28 /// Cumulative time spent scanning. | 26 /// Cumulative time spent scanning. |
29 Stopwatch scanTimer = new Stopwatch(); | 27 Stopwatch scanTimer = new Stopwatch(); |
30 | 28 |
31 main(List<String> args) async { | 29 main(List<String> args) async { |
32 // TODO(sigmund): provide sdk folder as well. | 30 // TODO(sigmund): provide sdk folder as well. |
33 if (args.length < 2) { | 31 if (args.length < 2) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 helper(uri.resolve(directiveUri)); | 150 helper(uri.resolve(directiveUri)); |
153 } | 151 } |
154 } | 152 } |
155 | 153 |
156 helper(start); | 154 helper(start); |
157 } | 155 } |
158 | 156 |
159 /// Parse [contents] as a Dart program and return the URIs that appear in its | 157 /// Parse [contents] as a Dart program and return the URIs that appear in its |
160 /// import, export, and part directives. | 158 /// import, export, and part directives. |
161 Set<String> extractDirectiveUris(List<int> contents) { | 159 Set<String> extractDirectiveUris(List<int> contents) { |
162 var listener = new DirectiveListenerWithNative(); | 160 var listener = new DirectiveListener(acceptsNativeClause: true); |
163 new TopLevelParser(listener).parseUnit(tokenize(contents)); | 161 new TopLevelParser(listener).parseUnit(tokenize(contents)); |
164 return new Set<String>() | 162 return new Set<String>() |
165 ..addAll(listener.imports) | 163 ..addAll(listener.imports) |
166 ..addAll(listener.exports) | 164 ..addAll(listener.exports) |
167 ..addAll(listener.parts); | 165 ..addAll(listener.parts); |
168 } | 166 } |
169 | 167 |
170 class DirectiveListenerWithNative extends DirectiveListener { | |
171 @override | |
172 Token handleNativeClause(Token token) => skipNativeClause(token); | |
173 } | |
174 | |
175 /// Parses every file in [files] and reports the time spent doing so. | 168 /// Parses every file in [files] and reports the time spent doing so. |
176 void parseFiles(Map<Uri, List<int>> files) { | 169 void parseFiles(Map<Uri, List<int>> files) { |
177 scanTimer = new Stopwatch(); | 170 scanTimer = new Stopwatch(); |
178 var parseTimer = new Stopwatch()..start(); | 171 var parseTimer = new Stopwatch()..start(); |
179 files.forEach((uri, source) { | 172 files.forEach((uri, source) { |
180 parseFull(uri, source); | 173 parseFull(uri, source); |
181 }); | 174 }); |
182 parseTimer.stop(); | 175 parseTimer.stop(); |
183 | 176 |
184 report('scan', scanTimer.elapsedMicroseconds); | 177 report('scan', scanTimer.elapsedMicroseconds); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 /// Report that metric [name] took [time] micro-seconds to process | 245 /// Report that metric [name] took [time] micro-seconds to process |
253 /// [inputSize] characters. | 246 /// [inputSize] characters. |
254 void report(String name, int time) { | 247 void report(String name, int time) { |
255 var sb = new StringBuffer(); | 248 var sb = new StringBuffer(); |
256 var padding = ' ' * (20 - name.length); | 249 var padding = ' ' * (20 - name.length); |
257 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); | 250 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); |
258 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); | 251 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); |
259 sb.write(', $invSpeed ns/char'); | 252 sb.write(', $invSpeed ns/char'); |
260 print('$sb'); | 253 print('$sb'); |
261 } | 254 } |
OLD | NEW |