Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: pkg/front_end/tool/fasta_perf.dart

Issue 2865843002: Use FileSystem to read files in SourceLoader and TranslateUri. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/src/fasta/dill/dill_target.dart' show DillTarget; 13 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget;
13 import 'package:front_end/src/fasta/kernel/kernel_target.dart' 14 import 'package:front_end/src/fasta/kernel/kernel_target.dart'
14 show KernelTarget; 15 show KernelTarget;
15 import 'package:front_end/src/fasta/parser.dart'; 16 import 'package:front_end/src/fasta/parser.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/source/directive_listener.dart';
19 import 'package:front_end/src/fasta/ticker.dart' show Ticker; 20 import 'package:front_end/src/fasta/ticker.dart' show Ticker;
20 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; 21 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri;
21 import 'package:front_end/src/fasta/translate_uri.dart'; 22 import 'package:front_end/src/fasta/translate_uri.dart';
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 /// Translates `dart:*` and `package:*` URIs to resolved URIs. 77 /// Translates `dart:*` and `package:*` URIs to resolved URIs.
77 TranslateUri uriResolver; 78 TranslateUri uriResolver;
78 79
79 /// Preliminary set up to be able to correctly resolve URIs on the given 80 /// Preliminary set up to be able to correctly resolve URIs on the given
80 /// program. 81 /// program.
81 Future setup(Uri entryUri) async { 82 Future setup(Uri entryUri) async {
82 // TODO(sigmund): use `perf.dart::_findSdkPath` here when fasta can patch the 83 // TODO(sigmund): use `perf.dart::_findSdkPath` here when fasta can patch the
83 // sdk directly. 84 // sdk directly.
84 var sdkRoot = 85 var sdkRoot =
85 Uri.base.resolve(Platform.resolvedExecutable).resolve('patched_sdk/'); 86 Uri.base.resolve(Platform.resolvedExecutable).resolve('patched_sdk/');
86 uriResolver = await TranslateUri.parse(sdkRoot); 87 uriResolver = await TranslateUri.parse(PhysicalFileSystem.instance, sdkRoot);
87 } 88 }
88 89
89 /// Scan [contents] and return the first token produced by the scanner. 90 /// Scan [contents] and return the first token produced by the scanner.
90 Token tokenize(List<int> contents) { 91 Token tokenize(List<int> contents) {
91 scanTimer.start(); 92 scanTimer.start();
92 var token = scan(contents).tokens; 93 var token = scan(contents).tokens;
93 scanTimer.stop(); 94 scanTimer.stop();
94 return token; 95 return token;
95 } 96 }
96 97
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // TODO(sigmund): update to use the frontend api once fasta is being hit. 208 // TODO(sigmund): update to use the frontend api once fasta is being hit.
208 generateKernel(Uri entryUri, 209 generateKernel(Uri entryUri,
209 {bool compileSdk: true, bool strongMode: false}) async { 210 {bool compileSdk: true, bool strongMode: false}) async {
210 // TODO(sigmund): this is here only to compute the input size, 211 // TODO(sigmund): this is here only to compute the input size,
211 // we should extract the input size from the frontend instead. 212 // we should extract the input size from the frontend instead.
212 scanReachableFiles(entryUri); 213 scanReachableFiles(entryUri);
213 214
214 var timer = new Stopwatch()..start(); 215 var timer = new Stopwatch()..start();
215 final Ticker ticker = new Ticker(); 216 final Ticker ticker = new Ticker();
216 final DillTarget dillTarget = new DillTarget(ticker, uriResolver); 217 final DillTarget dillTarget = new DillTarget(ticker, uriResolver);
217 final KernelTarget kernelTarget = 218 final KernelTarget kernelTarget = new KernelTarget(
218 new KernelTarget(dillTarget, uriResolver, strongMode); 219 PhysicalFileSystem.instance, dillTarget, uriResolver, strongMode);
219 var entrypoints = [ 220 var entrypoints = [
220 entryUri, 221 entryUri,
221 // These extra libraries are added to match the same set of libraries 222 // These extra libraries are added to match the same set of libraries
222 // scanned by default by the VM and the other benchmarks. 223 // scanned by default by the VM and the other benchmarks.
223 Uri.parse('dart:async'), 224 Uri.parse('dart:async'),
224 Uri.parse('dart:collection'), 225 Uri.parse('dart:collection'),
225 Uri.parse('dart:convert'), 226 Uri.parse('dart:convert'),
226 Uri.parse('dart:core'), 227 Uri.parse('dart:core'),
227 Uri.parse('dart:developer'), 228 Uri.parse('dart:developer'),
228 Uri.parse('dart:_internal'), 229 Uri.parse('dart:_internal'),
(...skipping 23 matching lines...) Expand all
252 /// Report that metric [name] took [time] micro-seconds to process 253 /// Report that metric [name] took [time] micro-seconds to process
253 /// [inputSize] characters. 254 /// [inputSize] characters.
254 void report(String name, int time) { 255 void report(String name, int time) {
255 var sb = new StringBuffer(); 256 var sb = new StringBuffer();
256 var padding = ' ' * (20 - name.length); 257 var padding = ' ' * (20 - name.length);
257 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); 258 sb.write('$name:$padding $time us, ${time ~/ 1000} ms');
258 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); 259 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2);
259 sb.write(', $invSpeed ns/char'); 260 sb.write(', $invSpeed ns/char');
260 print('$sb'); 261 print('$sb');
261 } 262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698