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/physical_file_system.dart'; | 12 import 'package:front_end/physical_file_system.dart'; |
13 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; | 13 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; |
14 import 'package:front_end/src/fasta/kernel/kernel_target.dart' | 14 import 'package:front_end/src/fasta/kernel/kernel_target.dart' |
15 show KernelTarget; | 15 show KernelTarget; |
16 import 'package:front_end/src/fasta/parser.dart'; | 16 import 'package:front_end/src/fasta/parser.dart'; |
17 import 'package:front_end/src/fasta/scanner.dart'; | 17 import 'package:front_end/src/fasta/scanner.dart'; |
18 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; | 18 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; |
19 import 'package:front_end/src/fasta/source/directive_listener.dart'; | 19 import 'package:front_end/src/fasta/source/directive_listener.dart'; |
20 import 'package:front_end/src/fasta/ticker.dart' show Ticker; | 20 import 'package:front_end/src/fasta/ticker.dart' show Ticker; |
21 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; | 21 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; |
22 import 'package:front_end/src/fasta/translate_uri.dart'; | 22 import 'package:front_end/src/fasta/translate_uri.dart'; |
23 import 'package:front_end/src/fasta/parser/dart_vm_native.dart' | 23 import 'package:front_end/src/fasta/parser/dart_vm_native.dart' |
24 show skipNativeClause; | 24 show skipNativeClause; |
25 import 'package:kernel/target/targets.dart' show TargetFlags; | 25 import 'package:kernel/target/targets.dart' show TargetFlags; |
| 26 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; |
26 | 27 |
27 /// Cumulative total number of chars scanned. | 28 /// Cumulative total number of chars scanned. |
28 int inputSize = 0; | 29 int inputSize = 0; |
29 | 30 |
30 /// Cumulative time spent scanning. | 31 /// Cumulative time spent scanning. |
31 Stopwatch scanTimer = new Stopwatch(); | 32 Stopwatch scanTimer = new Stopwatch(); |
32 | 33 |
33 main(List<String> args) async { | 34 main(List<String> args) async { |
34 // TODO(sigmund): provide sdk folder as well. | 35 // TODO(sigmund): provide sdk folder as well. |
35 if (args.length < 2) { | 36 if (args.length < 2) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // Invoke the fasta kernel generator for the program starting in [entryUri] | 209 // Invoke the fasta kernel generator for the program starting in [entryUri] |
209 // TODO(sigmund): update to use the frontend api once fasta is being hit. | 210 // TODO(sigmund): update to use the frontend api once fasta is being hit. |
210 generateKernel(Uri entryUri, | 211 generateKernel(Uri entryUri, |
211 {bool compileSdk: true, bool strongMode: false}) async { | 212 {bool compileSdk: true, bool strongMode: false}) async { |
212 // TODO(sigmund): this is here only to compute the input size, | 213 // TODO(sigmund): this is here only to compute the input size, |
213 // we should extract the input size from the frontend instead. | 214 // we should extract the input size from the frontend instead. |
214 scanReachableFiles(entryUri); | 215 scanReachableFiles(entryUri); |
215 | 216 |
216 var timer = new Stopwatch()..start(); | 217 var timer = new Stopwatch()..start(); |
217 final Ticker ticker = new Ticker(); | 218 final Ticker ticker = new Ticker(); |
218 final DillTarget dillTarget = new DillTarget(ticker, uriResolver, "vm_fasta", | 219 final DillTarget dillTarget = new DillTarget(ticker, uriResolver, |
219 flags: new TargetFlags(strongMode: strongMode)); | 220 new VmFastaTarget(new TargetFlags(strongMode: strongMode))); |
220 final KernelTarget kernelTarget = | 221 final KernelTarget kernelTarget = |
221 new KernelTarget(PhysicalFileSystem.instance, dillTarget, uriResolver); | 222 new KernelTarget(PhysicalFileSystem.instance, dillTarget, uriResolver); |
222 var entrypoints = [ | 223 var entrypoints = [ |
223 entryUri, | 224 entryUri, |
224 // These extra libraries are added to match the same set of libraries | 225 // These extra libraries are added to match the same set of libraries |
225 // scanned by default by the VM and the other benchmarks. | 226 // scanned by default by the VM and the other benchmarks. |
226 Uri.parse('dart:async'), | 227 Uri.parse('dart:async'), |
227 Uri.parse('dart:collection'), | 228 Uri.parse('dart:collection'), |
228 Uri.parse('dart:convert'), | 229 Uri.parse('dart:convert'), |
229 Uri.parse('dart:core'), | 230 Uri.parse('dart:core'), |
(...skipping 25 matching lines...) Expand all Loading... |
255 /// Report that metric [name] took [time] micro-seconds to process | 256 /// Report that metric [name] took [time] micro-seconds to process |
256 /// [inputSize] characters. | 257 /// [inputSize] characters. |
257 void report(String name, int time) { | 258 void report(String name, int time) { |
258 var sb = new StringBuffer(); | 259 var sb = new StringBuffer(); |
259 var padding = ' ' * (20 - name.length); | 260 var padding = ' ' * (20 - name.length); |
260 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); | 261 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); |
261 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); | 262 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); |
262 sb.write(', $invSpeed ns/char'); | 263 sb.write(', $invSpeed ns/char'); |
263 print('$sb'); | 264 print('$sb'); |
264 } | 265 } |
OLD | NEW |