| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 front_end and measure its performance. | 5 /// An entrypoint used to run portions of front_end and measure its performance. |
| 6 library front_end.tool.perf; | 6 library front_end.tool.perf; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io' show exit, stderr; | 9 import 'dart:io' show exit, stderr; |
| 10 | 10 |
| 11 import 'package:analyzer/dart/ast/ast.dart'; | 11 import 'package:analyzer/dart/ast/ast.dart'; |
| 12 import 'package:analyzer/dart/ast/token.dart'; | |
| 13 import 'package:analyzer/error/listener.dart'; | 12 import 'package:analyzer/error/listener.dart'; |
| 14 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; | 13 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; |
| 15 import 'package:analyzer/file_system/physical_file_system.dart' | 14 import 'package:analyzer/file_system/physical_file_system.dart' |
| 16 show PhysicalResourceProvider; | 15 show PhysicalResourceProvider; |
| 17 import 'package:analyzer/source/package_map_resolver.dart'; | 16 import 'package:analyzer/source/package_map_resolver.dart'; |
| 18 import 'package:analyzer/src/context/builder.dart'; | 17 import 'package:analyzer/src/context/builder.dart'; |
| 19 import 'package:analyzer/src/dart/scanner/reader.dart'; | |
| 20 import 'package:analyzer/src/dart/scanner/scanner.dart'; | |
| 21 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; | 18 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; |
| 22 import 'package:analyzer/src/generated/parser.dart'; | 19 import 'package:analyzer/src/generated/parser.dart'; |
| 23 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 24 import 'package:analyzer/src/generated/source_io.dart'; | 21 import 'package:analyzer/src/generated/source_io.dart'; |
| 25 import 'package:kernel/analyzer/loader.dart'; | 22 import 'package:kernel/analyzer/loader.dart'; |
| 26 import 'package:kernel/kernel.dart'; | 23 import 'package:kernel/kernel.dart'; |
| 27 import 'package:package_config/discovery.dart'; | 24 import 'package:package_config/discovery.dart'; |
| 28 | 25 |
| 26 import 'package:front_end/src/scanner/reader.dart'; |
| 27 import 'package:front_end/src/scanner/scanner.dart'; |
| 28 import 'package:front_end/src/scanner/token.dart'; |
| 29 |
| 29 /// Cumulative total number of chars scanned. | 30 /// Cumulative total number of chars scanned. |
| 30 int scanTotalChars = 0; | 31 int scanTotalChars = 0; |
| 31 | 32 |
| 32 /// Cumulative time spent scanning. | 33 /// Cumulative time spent scanning. |
| 33 Stopwatch scanTimer = new Stopwatch(); | 34 Stopwatch scanTimer = new Stopwatch(); |
| 34 | 35 |
| 35 /// Factory to load and resolve app, packages, and sdk sources. | 36 /// Factory to load and resolve app, packages, and sdk sources. |
| 36 SourceFactory sources; | 37 SourceFactory sources; |
| 37 | 38 |
| 38 main(List<String> args) async { | 39 main(List<String> args) async { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 return parser.parseCompilationUnit(token); | 199 return parser.parseCompilationUnit(token); |
| 199 } | 200 } |
| 200 | 201 |
| 201 /// Scan [source] and return the first token produced by the scanner. | 202 /// Scan [source] and return the first token produced by the scanner. |
| 202 Token tokenize(Source source) { | 203 Token tokenize(Source source) { |
| 203 scanTimer.start(); | 204 scanTimer.start(); |
| 204 var contents = source.contents.data; | 205 var contents = source.contents.data; |
| 205 scanTotalChars += contents.length; | 206 scanTotalChars += contents.length; |
| 206 // TODO(sigmund): is there a way to scan from a random-access-file without | 207 // TODO(sigmund): is there a way to scan from a random-access-file without |
| 207 // first converting to String? | 208 // first converting to String? |
| 208 var scanner = new Scanner(source, new CharSequenceReader(contents), | 209 var scanner = new _Scanner(contents); |
| 209 AnalysisErrorListener.NULL_LISTENER)..preserveComments = false; | |
| 210 var token = scanner.tokenize(); | 210 var token = scanner.tokenize(); |
| 211 scanTimer.stop(); | 211 scanTimer.stop(); |
| 212 return token; | 212 return token; |
| 213 } | 213 } |
| 214 | 214 |
| 215 class _Scanner extends Scanner { |
| 216 _Scanner(String contents) : super(new CharSequenceReader(contents)) { |
| 217 preserveComments = false; |
| 218 } |
| 219 |
| 220 @override |
| 221 void reportError(errorCode, int offset, List<Object> arguments) { |
| 222 // ignore errors. |
| 223 } |
| 224 } |
| 225 |
| 215 /// Report that metric [name] took [time] micro-seconds to process | 226 /// Report that metric [name] took [time] micro-seconds to process |
| 216 /// [scanTotalChars] characters. | 227 /// [scanTotalChars] characters. |
| 217 void report(String name, int time) { | 228 void report(String name, int time) { |
| 218 var sb = new StringBuffer(); | 229 var sb = new StringBuffer(); |
| 219 sb.write('$name: $time us, ${time ~/ 1000} ms'); | 230 sb.write('$name: $time us, ${time ~/ 1000} ms'); |
| 220 sb.write(', ${scanTotalChars * 1000 ~/ time} chars/ms'); | 231 sb.write(', ${scanTotalChars * 1000 ~/ time} chars/ms'); |
| 221 print('$sb'); | 232 print('$sb'); |
| 222 } | 233 } |
| 223 | 234 |
| 224 // TODO(sigmund): replace this once kernel is produced by the frontend directly. | 235 // TODO(sigmund): replace this once kernel is produced by the frontend directly. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 236 const int errorLimit = 100; | 247 const int errorLimit = 100; |
| 237 stderr.writeln(errors.take(errorLimit).join('\n')); | 248 stderr.writeln(errors.take(errorLimit).join('\n')); |
| 238 if (errors.length > errorLimit) { | 249 if (errors.length > errorLimit) { |
| 239 stderr.writeln('[error] ${errors.length - errorLimit} errors not shown'); | 250 stderr.writeln('[error] ${errors.length - errorLimit} errors not shown'); |
| 240 } | 251 } |
| 241 } | 252 } |
| 242 dartkTimer.stop(); | 253 dartkTimer.stop(); |
| 243 report("kernel_gen_e2e", dartkTimer.elapsedMicroseconds); | 254 report("kernel_gen_e2e", dartkTimer.elapsedMicroseconds); |
| 244 return program; | 255 return program; |
| 245 } | 256 } |
| OLD | NEW |