Chromium Code Reviews| Index: pkg/compiler/lib/src/apiimpl.dart |
| diff --git a/pkg/compiler/lib/src/apiimpl.dart b/pkg/compiler/lib/src/apiimpl.dart |
| index 75ecf88a5b96519e5601d4ca99c95b05213288fc..b8b3a78c4052b45506f5812363bb9ab648e2cf41 100644 |
| --- a/pkg/compiler/lib/src/apiimpl.dart |
| +++ b/pkg/compiler/lib/src/apiimpl.dart |
| @@ -19,7 +19,8 @@ import '../compiler_new.dart' as api; |
| import 'commandline_options.dart'; |
| import 'common.dart'; |
| import 'common/tasks.dart' show |
| - GenericTask; |
| + GenericTask, |
| + Measurer; |
| import 'common/backend_api.dart' show |
| Backend; |
| import 'compiler.dart'; |
| @@ -44,28 +45,8 @@ const String _dart2dartPlatform = "lib/dart2dart.platform"; |
| /// Implements the [Compiler] using a [api.CompilerInput] for supplying the |
| /// sources. |
| class CompilerImpl extends Compiler { |
| - api.CompilerInput provider; |
| - api.CompilerDiagnostics handler; |
| - final Uri platformConfigUri; |
| - final Uri packageConfig; |
| - final Uri packageRoot; |
| - final api.PackagesDiscoveryProvider packagesDiscoveryProvider; |
| - Packages packages; |
| - List<String> options; |
| - Map<String, dynamic> environment; |
| - bool mockableLibraryUsed = false; |
| - |
| - /// A mapping of the dart: library-names to their location. |
| - /// |
| - /// Initialized in [setupSdk]. |
| - Map<String, Uri> sdkLibraries; |
| - |
| - GenericTask userHandlerTask; |
| - GenericTask userProviderTask; |
| - GenericTask userPackagesDiscoveryTask; |
| - |
| - Uri get libraryRoot => platformConfigUri.resolve("."); |
| - |
| + // Constructor must be first to ensure [Measurer] is instantiated before |
| + // other computations. |
| CompilerImpl(this.provider, |
| api.CompilerOutput outputProvider, |
| this.handler, |
| @@ -75,10 +56,10 @@ class CompilerImpl extends Compiler { |
| this.environment, |
| [this.packageConfig, |
| this.packagesDiscoveryProvider, |
| - Backend makeBackend(Compiler compiler)]) |
| - : this.options = options, |
| - this.platformConfigUri = resolvePlatformConfig(libraryRoot, options), |
| - super( |
| + Backend makeBackend(Compiler compiler), |
| + Measurer measurer]) |
| + : super( // Call super first to ensure Measurer is instantiated first. |
|
floitsch
2016/01/07 14:40:39
Tbh I would prefer if super stays last, and you ju
ahe
2016/01/08 09:02:01
Code removed, but FWIW, I can't use a factory cons
|
| + measurer: measurer == null ? new Measurer() : measurer, |
|
floitsch
2016/01/07 14:40:39
measurer ?? new Measurer()
ahe
2016/01/08 09:02:01
Code removed.
|
| outputProvider: outputProvider, |
| enableTypeAssertions: hasOption(options, Flags.enableCheckedMode), |
| enableUserAssertions: hasOption(options, Flags.enableCheckedMode), |
| @@ -136,7 +117,9 @@ class CompilerImpl extends Compiler { |
| testMode: hasOption(options, Flags.testMode), |
| allowNativeExtensions: |
| hasOption(options, Flags.allowNativeExtensions), |
| - makeBackend: makeBackend) { |
| + makeBackend: makeBackend), |
| + this.options = options, |
| + this.platformConfigUri = resolvePlatformConfig(libraryRoot, options) { |
| tasks.addAll([ |
| userHandlerTask = new GenericTask('Diagnostic handler', this), |
| userProviderTask = new GenericTask('Input provider', this), |
| @@ -165,6 +148,28 @@ class CompilerImpl extends Compiler { |
| } |
| } |
| + api.CompilerInput provider; |
| + api.CompilerDiagnostics handler; |
| + final Uri platformConfigUri; |
| + final Uri packageConfig; |
| + final Uri packageRoot; |
| + final api.PackagesDiscoveryProvider packagesDiscoveryProvider; |
| + Packages packages; |
| + List<String> options; |
| + Map<String, dynamic> environment; |
| + bool mockableLibraryUsed = false; |
| + |
| + /// A mapping of the dart: library-names to their location. |
| + /// |
| + /// Initialized in [setupSdk]. |
| + Map<String, Uri> sdkLibraries; |
| + |
| + GenericTask userHandlerTask; |
| + GenericTask userProviderTask; |
| + GenericTask userPackagesDiscoveryTask; |
| + |
| + Uri get libraryRoot => platformConfigUri.resolve("."); |
| + |
| static String extractStringOption(List<String> options, |
| String prefix, |
| String defaultValue) { |
| @@ -411,14 +416,9 @@ class CompilerImpl extends Compiler { |
| Future<elements.LibraryElement> analyzeUri( |
| Uri uri, |
| {bool skipLibraryWithPartOfTag: true}) { |
| - List<Future> setupFutures = new List<Future>(); |
| - if (sdkLibraries == null) { |
| - setupFutures.add(setupSdk()); |
| - } |
| - if (packages == null) { |
| - setupFutures.add(setupPackages(uri)); |
| - } |
| - return Future.wait(setupFutures).then((_) => super.analyzeUri(uri)); |
| + return new Future(() => (sdkLibraries == null) ? setupSdk() : null) |
| + .then((_) => packages == null ? setupPackages(uri) : null) |
| + .then((_) => super.analyzeUri(uri)); |
| } |
| Future setupPackages(Uri uri) { |
| @@ -473,28 +473,47 @@ class CompilerImpl extends Compiler { |
| } |
| Future<bool> run(Uri uri) { |
| - log('Using platform configuration at ${platformConfigUri}'); |
| - |
| - return Future.wait([setupSdk(), setupPackages(uri)]).then((_) { |
| - assert(sdkLibraries != null); |
| - assert(packages != null); |
| - |
| - return super.run(uri).then((bool success) { |
| - int cumulated = 0; |
| + Duration setupDuration = measurer.wallClock.elapsed; |
| + return selfTask.measureSubtask("CompilerImpl.run", () { |
| + log('Using platform configuration at ${platformConfigUri}'); |
| + |
| + return setupSdk().then((_) => setupPackages(uri)).then((_) { |
| + assert(sdkLibraries != null); |
| + assert(packages != null); |
| + return super.run(uri); |
| + }).then((bool success) { |
| + StringBuffer timings = new StringBuffer(); |
| + timings.writeln("Timings:"); |
| + Duration totalDuration = measurer.wallClock.elapsed; |
| + Duration asyncDuration = measurer.asyncWallClock.elapsed; |
| + Duration cumulatedDuration = Duration.ZERO; |
| for (final task in tasks) { |
| - int elapsed = task.timing; |
| - if (elapsed != 0) { |
| - cumulated += elapsed; |
| - log('${task.name} took ${elapsed}msec'); |
| + String running = task.isRunning ? "*" : ""; |
| + Duration duration = task.duration; |
| + if (duration != Duration.ZERO) { |
| + cumulatedDuration += duration; |
| + timings.writeln( |
| + ' $running${task.name} took' |
| + ' ${duration.inMilliseconds}msec'); |
| for (String subtask in task.subtasks) { |
| int subtime = task.getSubtaskTime(subtask); |
| - log('${task.name} > $subtask took ${subtime}msec'); |
| + String running = task.getSubtaskIsRunning(subtask) ? "*" : ""; |
| + timings.writeln( |
| + ' $running${task.name} > $subtask took ${subtime}msec'); |
| } |
| } |
| } |
| - int total = totalCompileTime.elapsedMilliseconds; |
| - log('Total compile-time ${total}msec;' |
| - ' unaccounted ${total - cumulated}msec'); |
| + Duration unaccountedDuration = |
| + totalDuration - cumulatedDuration - setupDuration - asyncDuration; |
| + Double percent = unaccountedDuration.inMilliseconds * 100 |
|
floitsch
2016/01/07 14:40:39
double is lower case.
ahe
2016/01/08 09:02:02
Done.
|
| + / totalDuration.inMilliseconds; |
| + timings.write( |
| + ' Total compile-time ${totalDuration.inMilliseconds}msec;' |
| + ' setup ${setupDuration.inMilliseconds}msec;' |
| + ' async ${asyncDuration.inMilliseconds}msec;' |
| + ' unaccounted ${unaccountedDuration.inMilliseconds}msec' |
| + ' (${percent.toStringAsFixed(2)}%)'); |
| + log("$timings"); |
| return success; |
| }); |
| }); |
| @@ -543,7 +562,7 @@ class CompilerImpl extends Compiler { |
| Future callUserProvider(Uri uri) { |
| try { |
| - return userProviderTask.measure(() => provider.readFromUri(uri)); |
| + return userProviderTask.measureIo(() => provider.readFromUri(uri)); |
| } catch (ex, s) { |
| diagnoseCrashInUserCode('Uncaught exception in input provider', ex, s); |
| rethrow; |
| @@ -552,7 +571,7 @@ class CompilerImpl extends Compiler { |
| Future<Packages> callUserPackagesDiscovery(Uri uri) { |
| try { |
| - return userPackagesDiscoveryTask.measure( |
| + return userPackagesDiscoveryTask.measureIo( |
| () => packagesDiscoveryProvider(uri)); |
| } catch (ex, s) { |
| diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s); |