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/front_end.dart'; | 12 import 'package:front_end/front_end.dart'; |
13 import 'package:front_end/physical_file_system.dart'; | 13 import 'package:front_end/src/base/processed_options.dart'; |
14 import 'package:front_end/src/fasta/parser.dart'; | 14 import 'package:front_end/src/fasta/parser.dart'; |
15 import 'package:front_end/src/fasta/scanner.dart'; | 15 import 'package:front_end/src/fasta/scanner.dart'; |
16 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; | 16 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; |
17 import 'package:front_end/src/fasta/source/directive_listener.dart'; | 17 import 'package:front_end/src/fasta/source/directive_listener.dart'; |
18 import 'package:front_end/src/fasta/uri_translator.dart' show UriTranslator; | 18 import 'package:front_end/src/fasta/uri_translator.dart' show UriTranslator; |
19 import 'package:front_end/src/fasta/parser/native_support.dart' | 19 import 'package:front_end/src/fasta/parser/native_support.dart' |
20 show skipNativeClause; | 20 show skipNativeClause; |
21 import 'package:front_end/src/fasta/uri_translator_impl.dart'; | |
22 | 21 |
23 /// Cumulative total number of chars scanned. | 22 /// Cumulative total number of chars scanned. |
24 int inputSize = 0; | 23 int inputSize = 0; |
25 | 24 |
26 /// Cumulative time spent scanning. | 25 /// Cumulative time spent scanning. |
27 Stopwatch scanTimer = new Stopwatch(); | 26 Stopwatch scanTimer = new Stopwatch(); |
28 | 27 |
29 main(List<String> args) async { | 28 main(List<String> args) async { |
30 // TODO(sigmund): provide sdk folder as well. | 29 // TODO(sigmund): provide sdk folder as well. |
31 if (args.length < 2) { | 30 if (args.length < 2) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // sdk directly. | 72 // sdk directly. |
74 Uri sdkRoot = | 73 Uri sdkRoot = |
75 Uri.base.resolve(Platform.resolvedExecutable).resolve('patched_sdk/'); | 74 Uri.base.resolve(Platform.resolvedExecutable).resolve('patched_sdk/'); |
76 | 75 |
77 /// Translates `dart:*` and `package:*` URIs to resolved URIs. | 76 /// Translates `dart:*` and `package:*` URIs to resolved URIs. |
78 UriTranslator uriResolver; | 77 UriTranslator uriResolver; |
79 | 78 |
80 /// Preliminary set up to be able to correctly resolve URIs on the given | 79 /// Preliminary set up to be able to correctly resolve URIs on the given |
81 /// program. | 80 /// program. |
82 Future setup(Uri entryUri) async { | 81 Future setup(Uri entryUri) async { |
83 uriResolver = | 82 var options = new CompilerOptions() |
84 await UriTranslatorImpl.parse(PhysicalFileSystem.instance, sdkRoot); | 83 ..sdkRoot = sdkRoot |
| 84 ..compileSdk = true |
| 85 ..packagesFileUri = Uri.base.resolve('.packages'); |
| 86 uriResolver = await new ProcessedOptions(options).getUriTranslator(); |
85 } | 87 } |
86 | 88 |
87 /// Scan [contents] and return the first token produced by the scanner. | 89 /// Scan [contents] and return the first token produced by the scanner. |
88 Token tokenize(List<int> contents) { | 90 Token tokenize(List<int> contents) { |
89 scanTimer.start(); | 91 scanTimer.start(); |
90 var token = scan(contents).tokens; | 92 var token = scan(contents).tokens; |
91 scanTimer.stop(); | 93 scanTimer.stop(); |
92 return token; | 94 return token; |
93 } | 95 } |
94 | 96 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 /// Report that metric [name] took [time] micro-seconds to process | 247 /// Report that metric [name] took [time] micro-seconds to process |
246 /// [inputSize] characters. | 248 /// [inputSize] characters. |
247 void report(String name, int time) { | 249 void report(String name, int time) { |
248 var sb = new StringBuffer(); | 250 var sb = new StringBuffer(); |
249 var padding = ' ' * (20 - name.length); | 251 var padding = ' ' * (20 - name.length); |
250 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); | 252 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); |
251 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); | 253 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); |
252 sb.write(', $invSpeed ns/char'); | 254 sb.write(', $invSpeed ns/char'); |
253 print('$sb'); | 255 print('$sb'); |
254 } | 256 } |
OLD | NEW |