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