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

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

Issue 2687723002: Remove hardcoded paths from perf.dart. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | pkg/pkg.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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; 9 import 'dart:io' show Directory, File, Platform, exit;
10 10
11 import 'package:analyzer/dart/ast/ast.dart'; 11 import 'package:analyzer/dart/ast/ast.dart';
12 import 'package:analyzer/error/listener.dart'; 12 import 'package:analyzer/error/listener.dart';
13 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; 13 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver;
14 import 'package:analyzer/file_system/physical_file_system.dart' 14 import 'package:analyzer/file_system/physical_file_system.dart'
15 show PhysicalResourceProvider; 15 show PhysicalResourceProvider;
16 import 'package:analyzer/source/package_map_resolver.dart'; 16 import 'package:analyzer/source/package_map_resolver.dart';
17 import 'package:analyzer/src/context/builder.dart'; 17 import 'package:analyzer/src/context/builder.dart';
18 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; 18 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk;
19 import 'package:analyzer/src/generated/parser.dart'; 19 import 'package:analyzer/src/generated/parser.dart';
20 import 'package:analyzer/src/generated/source.dart'; 20 import 'package:analyzer/src/generated/source.dart';
21 import 'package:analyzer/src/generated/source_io.dart'; 21 import 'package:analyzer/src/generated/source_io.dart';
22 import 'package:analyzer/src/summary/format.dart'; 22 import 'package:analyzer/src/summary/format.dart';
23 import 'package:analyzer/src/summary/idl.dart'; 23 import 'package:analyzer/src/summary/idl.dart';
24 import 'package:analyzer/src/summary/link.dart'; 24 import 'package:analyzer/src/summary/link.dart';
25 import 'package:analyzer/src/summary/summarize_ast.dart'; 25 import 'package:analyzer/src/summary/summarize_ast.dart';
26 import 'package:front_end/compiler_options.dart'; 26 import 'package:front_end/compiler_options.dart';
27 import 'package:front_end/kernel_generator.dart'; 27 import 'package:front_end/kernel_generator.dart';
28 import 'package:front_end/src/scanner/reader.dart'; 28 import 'package:front_end/src/scanner/reader.dart';
29 import 'package:front_end/src/scanner/scanner.dart'; 29 import 'package:front_end/src/scanner/scanner.dart';
30 import 'package:front_end/src/scanner/token.dart'; 30 import 'package:front_end/src/scanner/token.dart';
31 import 'package:kernel/kernel.dart' hide Source; 31 import 'package:kernel/kernel.dart' hide Source;
32 import 'package:package_config/discovery.dart'; 32 import 'package:package_config/discovery.dart';
33 import 'package:path/path.dart' as path;
33 34
34 main(List<String> args) async { 35 main(List<String> args) async {
35 // TODO(sigmund): provide sdk folder as well. 36 // TODO(sigmund): provide sdk folder as well.
36 if (args.length < 2) { 37 if (args.length < 2) {
37 print('usage: perf.dart <bench-id> <entry.dart>'); 38 print('usage: perf.dart <bench-id> <entry.dart>');
38 exit(1); 39 exit(1);
39 } 40 }
40 41
41 var bench = args[0]; 42 var bench = args[0];
42 var entryUri = Uri.base.resolve(args[1]); 43 var entryUri = Uri.base.resolve(args[1]);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 86
86 /// Cumulative time spent scanning. 87 /// Cumulative time spent scanning.
87 Stopwatch scanTimer = new Stopwatch(); 88 Stopwatch scanTimer = new Stopwatch();
88 89
89 /// Size of all sources. 90 /// Size of all sources.
90 int inputSize = 0; 91 int inputSize = 0;
91 92
92 /// Factory to load and resolve app, packages, and sdk sources. 93 /// Factory to load and resolve app, packages, and sdk sources.
93 SourceFactory sources; 94 SourceFactory sources;
94 95
96 /// File URI of the root of the SDK source tree.
97 final _repoUri = Platform.script.resolve('../../../');
98
99 /// Path to the root of the built SDK that is being used to execute this script.
100 final _sdkPath = _findSdkPath();
101
102 /// File URI to the root of the built SDK that is being used to execute this
103 /// script.
104 final _sdkUri = new Uri.directory(_sdkPath);
105
95 /// Add to [files] all sources reachable from [start]. 106 /// Add to [files] all sources reachable from [start].
96 void collectSources(Source start, Set<Source> files) { 107 void collectSources(Source start, Set<Source> files) {
97 if (!files.add(start)) return; 108 if (!files.add(start)) return;
98 var unit = parseDirectives(start); 109 var unit = parseDirectives(start);
99 for (var directive in unit.directives) { 110 for (var directive in unit.directives) {
100 if (directive is UriBasedDirective) { 111 if (directive is UriBasedDirective) {
101 var next = sources.resolveUri(start, directive.uri.stringValue); 112 var next = sources.resolveUri(start, directive.uri.stringValue);
102 collectSources(next, files); 113 collectSources(next, files);
103 } 114 }
104 } 115 }
105 } 116 }
106 117
107 Future<Program> generateKernel(Uri entryUri, 118 Future<Program> generateKernel(Uri entryUri,
108 {bool useSdkSummary: false, bool compileSdk: true}) async { 119 {bool useSdkSummary: false, bool compileSdk: true}) async {
109 // TODO(sigmund): this is here only to compute the input size, 120 // TODO(sigmund): this is here only to compute the input size,
110 // we should extract the input size from the frontend instead. 121 // we should extract the input size from the frontend instead.
111 scanReachableFiles(entryUri); 122 scanReachableFiles(entryUri);
112 123
113 var dartkTimer = new Stopwatch()..start(); 124 var dartkTimer = new Stopwatch()..start();
114 // TODO(sigmund): add a constructor with named args to compiler options. 125 // TODO(sigmund): add a constructor with named args to compiler options.
115 var options = new CompilerOptions() 126 var options = new CompilerOptions()
116 ..strongMode = false 127 ..strongMode = false
117 ..compileSdk = compileSdk 128 ..compileSdk = compileSdk
118 ..packagesFileUri = Uri.base.resolve('.packages') 129 ..packagesFileUri = _repoUri.resolve('.packages')
119 ..onError = ((e) => print('${e.message}')); 130 ..onError = ((e) => print('${e.message}'));
120 if (useSdkSummary) { 131 if (useSdkSummary) {
121 // TODO(sigmund): adjust path based on the benchmark runner architecture. 132 // TODO(sigmund): adjust path based on the benchmark runner architecture.
Siggi Cherem (dart-lang) 2017/02/08 22:40:39 maybe we can remove the TODO then :)
Paul Berry 2017/02/09 00:41:50 Done.
122 // Possibly let the runner make the file available at an architecture 133 // Possibly let the runner make the file available at an architecture
123 // independent location. 134 // independent location.
124 options.sdkSummary = 135 options.sdkSummary = _sdkUri.resolve('lib/_internal/spec.sum');
125 Uri.base.resolve('out/ReleaseX64/dart-sdk/lib/_internal/spec.sum');
126 } else { 136 } else {
127 options.sdkRoot = Uri.base.resolve('sdk'); 137 options.sdkRoot = _sdkUri;
128 } 138 }
129 Program program = await kernelForProgram(entryUri, options); 139 Program program = await kernelForProgram(entryUri, options);
130 dartkTimer.stop(); 140 dartkTimer.stop();
131 var suffix = useSdkSummary ? '_sum' : ''; 141 var suffix = useSdkSummary ? '_sum' : '';
132 report('kernel_gen_e2e${suffix}', dartkTimer.elapsedMicroseconds); 142 report('kernel_gen_e2e${suffix}', dartkTimer.elapsedMicroseconds);
133 return program; 143 return program;
134 } 144 }
135 145
136 /// Generates unlinkmed summaries for all files in [files], and returns them in 146 /// Generates unlinkmed summaries for all files in [files], and returns them in
137 /// an [_UnlinkedSummaries] container. 147 /// an [_UnlinkedSummaries] container.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 /// Sets up analyzer to be able to load and resolve app, packages, and sdk 302 /// Sets up analyzer to be able to load and resolve app, packages, and sdk
293 /// sources. 303 /// sources.
294 Future setup(Uri entryUri) async { 304 Future setup(Uri entryUri) async {
295 var provider = PhysicalResourceProvider.INSTANCE; 305 var provider = PhysicalResourceProvider.INSTANCE;
296 var packageMap = new ContextBuilder(provider, null, null) 306 var packageMap = new ContextBuilder(provider, null, null)
297 .convertPackagesToMap(await findPackages(entryUri)); 307 .convertPackagesToMap(await findPackages(entryUri));
298 sources = new SourceFactory([ 308 sources = new SourceFactory([
299 new ResourceUriResolver(provider), 309 new ResourceUriResolver(provider),
300 new PackageMapUriResolver(provider, packageMap), 310 new PackageMapUriResolver(provider, packageMap),
301 new DartUriResolver( 311 new DartUriResolver(
302 new FolderBasedDartSdk(provider, provider.getFolder('sdk'))), 312 new FolderBasedDartSdk(provider, provider.getFolder(_sdkPath))),
303 ]); 313 ]);
304 } 314 }
305 315
306 /// Scan [source] and return the first token produced by the scanner. 316 /// Scan [source] and return the first token produced by the scanner.
307 Token tokenize(Source source) { 317 Token tokenize(Source source) {
308 scanTimer.start(); 318 scanTimer.start();
309 // TODO(sigmund): is there a way to scan from a random-access-file without 319 // TODO(sigmund): is there a way to scan from a random-access-file without
310 // first converting to String? 320 // first converting to String?
311 var scanner = new _Scanner(source.contents.data); 321 var scanner = new _Scanner(source.contents.data);
312 var token = scanner.tokenize(); 322 var token = scanner.tokenize();
313 scanTimer.stop(); 323 scanTimer.stop();
314 return token; 324 return token;
315 } 325 }
316 326
317 UnlinkedUnitBuilder unlinkedSummarize(Source source) { 327 UnlinkedUnitBuilder unlinkedSummarize(Source source) {
318 var unit = parseFull(source); 328 var unit = parseFull(source);
319 unlinkedSummarizeTimer.start(); 329 unlinkedSummarizeTimer.start();
320 var unlinkedUnit = serializeAstUnlinked(unit); 330 var unlinkedUnit = serializeAstUnlinked(unit);
321 unlinkedSummarizeTimer.stop(); 331 unlinkedSummarizeTimer.stop();
322 return unlinkedUnit; 332 return unlinkedUnit;
323 } 333 }
324 334
335 String _findSdkPath() {
336 var executable = Platform.resolvedExecutable;
337 var executableDir = path.dirname(executable);
338 for (var candidate in [
339 path.dirname(executableDir),
340 path.join(executableDir, 'dart-sdk')
341 ]) {
342 if (new File(path.join(candidate, 'lib', 'dart_server.platform'))
343 .existsSync()) {
344 return candidate;
345 }
346 }
347 // Not found; guess "sdk" relative to the current directory.
348 return new Directory('sdk').absolute.path;
349 }
350
325 /// Simple container for a mapping from URI string to an unlinked summary. 351 /// Simple container for a mapping from URI string to an unlinked summary.
326 class _UnlinkedSummaries { 352 class _UnlinkedSummaries {
327 final summariesByUri = <String, UnlinkedUnit>{}; 353 final summariesByUri = <String, UnlinkedUnit>{};
328 354
329 /// Get the unlinked summary for the given URI, and report a warning if it 355 /// Get the unlinked summary for the given URI, and report a warning if it
330 /// can't be found. 356 /// can't be found.
331 UnlinkedUnit getUnit(String uri) { 357 UnlinkedUnit getUnit(String uri) {
332 var result = summariesByUri[uri]; 358 var result = summariesByUri[uri];
333 if (result == null) { 359 if (result == null) {
334 print('Warning: no summary found for: $uri'); 360 print('Warning: no summary found for: $uri');
335 } 361 }
336 return result; 362 return result;
337 } 363 }
338 } 364 }
339 365
340 class _Scanner extends Scanner { 366 class _Scanner extends Scanner {
341 _Scanner(String contents) : super(new CharSequenceReader(contents)) { 367 _Scanner(String contents) : super(new CharSequenceReader(contents)) {
342 preserveComments = false; 368 preserveComments = false;
343 } 369 }
344 370
345 @override 371 @override
346 void reportError(errorCode, int offset, List<Object> arguments) { 372 void reportError(errorCode, int offset, List<Object> arguments) {
347 // ignore errors. 373 // ignore errors.
348 } 374 }
349 } 375 }
OLDNEW
« no previous file with comments | « no previous file | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698