| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library leg_apiimpl; | 5 library leg_apiimpl; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:package_config/packages.dart'; | 10 import 'package:package_config/packages.dart'; |
| 11 import 'package:package_config/packages_file.dart' as pkgs; | 11 import 'package:package_config/packages_file.dart' as pkgs; |
| 12 import 'package:package_config/src/packages_impl.dart' | 12 import 'package:package_config/src/packages_impl.dart' |
| 13 show MapPackages, NonFilePackagesDirectoryPackages; | 13 show MapPackages, NonFilePackagesDirectoryPackages; |
| 14 import 'package:package_config/src/util.dart' show checkValidPackageUri; | 14 import 'package:package_config/src/util.dart' show checkValidPackageUri; |
| 15 | 15 |
| 16 import '../compiler_new.dart' as api; | 16 import '../compiler_new.dart' as api; |
| 17 import 'common/tasks.dart' show GenericTask; | 17 import 'common/tasks.dart' show GenericTask, Measurer; |
| 18 import 'common.dart'; | 18 import 'common.dart'; |
| 19 import 'compiler.dart'; | 19 import 'compiler.dart'; |
| 20 import 'diagnostics/messages.dart' show Message; | 20 import 'diagnostics/messages.dart' show Message; |
| 21 import 'elements/elements.dart' as elements; | 21 import 'elements/elements.dart' as elements; |
| 22 import 'environment.dart'; | 22 import 'environment.dart'; |
| 23 import 'io/source_file.dart'; | 23 import 'io/source_file.dart'; |
| 24 import 'options.dart' show CompilerOptions; | 24 import 'options.dart' show CompilerOptions; |
| 25 import 'platform_configuration.dart' as platform_configuration; | 25 import 'platform_configuration.dart' as platform_configuration; |
| 26 import 'resolved_uri_translator.dart'; | 26 import 'resolved_uri_translator.dart'; |
| 27 import 'script.dart'; | 27 import 'script.dart'; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 152 } |
| 153 return packages.resolve(uri, notFound: (Uri notFound) { | 153 return packages.resolve(uri, notFound: (Uri notFound) { |
| 154 reporter.reportErrorMessage( | 154 reporter.reportErrorMessage( |
| 155 node, MessageKind.LIBRARY_NOT_FOUND, {'resolvedUri': uri}); | 155 node, MessageKind.LIBRARY_NOT_FOUND, {'resolvedUri': uri}); |
| 156 return null; | 156 return null; |
| 157 }); | 157 }); |
| 158 } | 158 } |
| 159 | 159 |
| 160 Future<elements.LibraryElement> analyzeUri(Uri uri, | 160 Future<elements.LibraryElement> analyzeUri(Uri uri, |
| 161 {bool skipLibraryWithPartOfTag: true}) { | 161 {bool skipLibraryWithPartOfTag: true}) { |
| 162 List<Future> setupFutures = new List<Future>(); | 162 Future setupFuture = new Future.value(); |
| 163 if (resolvedUriTranslator.isNotSet) { | 163 if (resolvedUriTranslator.isNotSet) { |
| 164 setupFutures.add(setupSdk()); | 164 setupFuture = setupFuture.then((_) => setupSdk()); |
| 165 } | 165 } |
| 166 if (packages == null) { | 166 if (packages == null) { |
| 167 setupFutures.add(setupPackages(uri)); | 167 setupFuture = setupFuture.then((_) => setupPackages(uri)); |
| 168 } | 168 } |
| 169 return Future.wait(setupFutures).then((_) { | 169 return setupFuture.then((_) { |
| 170 return super | 170 return super |
| 171 .analyzeUri(uri, skipLibraryWithPartOfTag: skipLibraryWithPartOfTag); | 171 .analyzeUri(uri, skipLibraryWithPartOfTag: skipLibraryWithPartOfTag); |
| 172 }); | 172 }); |
| 173 } | 173 } |
| 174 | 174 |
| 175 Future setupPackages(Uri uri) { | 175 Future setupPackages(Uri uri) { |
| 176 if (options.packageRoot != null) { | 176 if (options.packageRoot != null) { |
| 177 // Use "non-file" packages because the file version requires a [Directory] | 177 // Use "non-file" packages because the file version requires a [Directory] |
| 178 // and we can't depend on 'dart:io' classes. | 178 // and we can't depend on 'dart:io' classes. |
| 179 packages = new NonFilePackagesDirectoryPackages(options.packageRoot); | 179 packages = new NonFilePackagesDirectoryPackages(options.packageRoot); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 new ResolvedUriTranslator(mapping, reporter); | 217 new ResolvedUriTranslator(mapping, reporter); |
| 218 }); | 218 }); |
| 219 } else { | 219 } else { |
| 220 // The incremental compiler sets up the sdk before run. | 220 // The incremental compiler sets up the sdk before run. |
| 221 // Therefore this will be called a second time. | 221 // Therefore this will be called a second time. |
| 222 return new Future.value(null); | 222 return new Future.value(null); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 Future<bool> run(Uri uri) { | 226 Future<bool> run(Uri uri) { |
| 227 log('Using platform configuration at ${options.platformConfigUri}'); | 227 Duration setupDuration = measurer.wallClock.elapsed; |
| 228 return selfTask.measureSubtask("CompilerImpl.run", () { |
| 229 log('Using platform configuration at ${options.platformConfigUri}'); |
| 228 | 230 |
| 229 return Future.wait([setupSdk(), setupPackages(uri)]).then((_) { | 231 return setupSdk().then((_) => setupPackages(uri)).then((_) { |
| 230 assert(resolvedUriTranslator.isSet); | 232 assert(resolvedUriTranslator.isSet); |
| 231 assert(packages != null); | 233 assert(packages != null); |
| 232 | 234 |
| 233 return super.run(uri).then((bool success) { | 235 return super.run(uri); |
| 234 int cumulated = 0; | 236 }).then((bool success) { |
| 235 for (final task in tasks) { | 237 if (options.verbose) { |
| 236 int elapsed = task.timing; | 238 StringBuffer timings = new StringBuffer(); |
| 237 if (elapsed != 0) { | 239 computeTimings(setupDuration, timings); |
| 238 cumulated += elapsed; | 240 log("$timings"); |
| 239 log('${task.name} took ${elapsed}msec'); | |
| 240 for (String subtask in task.subtasks) { | |
| 241 int subtime = task.getSubtaskTime(subtask); | |
| 242 log('${task.name} > $subtask took ${subtime}msec'); | |
| 243 } | |
| 244 } | |
| 245 } | 241 } |
| 246 int total = totalCompileTime.elapsedMilliseconds; | |
| 247 log('Total compile-time ${total}msec;' | |
| 248 ' unaccounted ${total - cumulated}msec'); | |
| 249 return success; | 242 return success; |
| 250 }); | 243 }); |
| 251 }); | 244 }); |
| 252 } | 245 } |
| 253 | 246 |
| 247 void computeTimings(Duration setupDuration, StringBuffer timings) { |
| 248 timings.writeln("Timings:"); |
| 249 Duration totalDuration = measurer.wallClock.elapsed; |
| 250 Duration asyncDuration = measurer.asyncWallClock.elapsed; |
| 251 Duration cumulatedDuration = Duration.ZERO; |
| 252 for (final task in tasks) { |
| 253 String running = task.isRunning ? "*" : ""; |
| 254 Duration duration = task.duration; |
| 255 if (duration != Duration.ZERO) { |
| 256 cumulatedDuration += duration; |
| 257 timings.writeln( |
| 258 ' $running${task.name} took' |
| 259 ' ${duration.inMilliseconds}msec'); |
| 260 for (String subtask in task.subtasks) { |
| 261 int subtime = task.getSubtaskTime(subtask); |
| 262 String running = task.getSubtaskIsRunning(subtask) ? "*" : ""; |
| 263 timings.writeln( |
| 264 ' $running${task.name} > $subtask took ${subtime}msec'); |
| 265 } |
| 266 } |
| 267 } |
| 268 Duration unaccountedDuration = |
| 269 totalDuration - cumulatedDuration - setupDuration - asyncDuration; |
| 270 double percent = unaccountedDuration.inMilliseconds * 100 |
| 271 / totalDuration.inMilliseconds; |
| 272 timings.write( |
| 273 ' Total compile-time ${totalDuration.inMilliseconds}msec;' |
| 274 ' setup ${setupDuration.inMilliseconds}msec;' |
| 275 ' async ${asyncDuration.inMilliseconds}msec;' |
| 276 ' unaccounted ${unaccountedDuration.inMilliseconds}msec' |
| 277 ' (${percent.toStringAsFixed(2)}%)'); |
| 278 } |
| 279 |
| 254 void reportDiagnostic(DiagnosticMessage message, | 280 void reportDiagnostic(DiagnosticMessage message, |
| 255 List<DiagnosticMessage> infos, api.Diagnostic kind) { | 281 List<DiagnosticMessage> infos, api.Diagnostic kind) { |
| 256 _reportDiagnosticMessage(message, kind); | 282 _reportDiagnosticMessage(message, kind); |
| 257 for (DiagnosticMessage info in infos) { | 283 for (DiagnosticMessage info in infos) { |
| 258 _reportDiagnosticMessage(info, api.Diagnostic.INFO); | 284 _reportDiagnosticMessage(info, api.Diagnostic.INFO); |
| 259 } | 285 } |
| 260 } | 286 } |
| 261 | 287 |
| 262 void _reportDiagnosticMessage( | 288 void _reportDiagnosticMessage( |
| 263 DiagnosticMessage diagnosticMessage, api.Diagnostic kind) { | 289 DiagnosticMessage diagnosticMessage, api.Diagnostic kind) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 277 mockableLibraryUsed && options.allowMockCompilation; | 303 mockableLibraryUsed && options.allowMockCompilation; |
| 278 | 304 |
| 279 void callUserHandler(Message message, Uri uri, int begin, int end, | 305 void callUserHandler(Message message, Uri uri, int begin, int end, |
| 280 String text, api.Diagnostic kind) { | 306 String text, api.Diagnostic kind) { |
| 281 userHandlerTask.measure(() { | 307 userHandlerTask.measure(() { |
| 282 handler.report(message, uri, begin, end, text, kind); | 308 handler.report(message, uri, begin, end, text, kind); |
| 283 }); | 309 }); |
| 284 } | 310 } |
| 285 | 311 |
| 286 Future callUserProvider(Uri uri) { | 312 Future callUserProvider(Uri uri) { |
| 287 return userProviderTask.measure(() => provider.readFromUri(uri)); | 313 return userProviderTask.measureIo(() => provider.readFromUri(uri)); |
| 288 } | 314 } |
| 289 | 315 |
| 290 Future<Packages> callUserPackagesDiscovery(Uri uri) { | 316 Future<Packages> callUserPackagesDiscovery(Uri uri) { |
| 291 return userPackagesDiscoveryTask | 317 return userPackagesDiscoveryTask |
| 292 .measure(() => options.packagesDiscoveryProvider(uri)); | 318 .measureIo(() => options.packagesDiscoveryProvider(uri)); |
| 293 } | 319 } |
| 294 | 320 |
| 295 Uri resolvePatchUri(String libraryName) { | 321 Uri resolvePatchUri(String libraryName) { |
| 296 return backend.resolvePatchUri(libraryName, options.platformConfigUri); | 322 return backend.resolvePatchUri(libraryName, options.platformConfigUri); |
| 297 } | 323 } |
| 298 } | 324 } |
| 299 | 325 |
| 300 class _Environment implements Environment { | 326 class _Environment implements Environment { |
| 301 final Map<String, String> definitions; | 327 final Map<String, String> definitions; |
| 302 | 328 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 360 } |
| 335 } | 361 } |
| 336 | 362 |
| 337 /// For every 'dart:' library, a corresponding environment variable is set | 363 /// For every 'dart:' library, a corresponding environment variable is set |
| 338 /// to "true". The environment variable's name is the concatenation of | 364 /// to "true". The environment variable's name is the concatenation of |
| 339 /// this prefix and the name (without the 'dart:'. | 365 /// this prefix and the name (without the 'dart:'. |
| 340 /// | 366 /// |
| 341 /// For example 'dart:html' has the environment variable 'dart.library.html' set | 367 /// For example 'dart:html' has the environment variable 'dart.library.html' set |
| 342 /// to "true". | 368 /// to "true". |
| 343 const String _dartLibraryEnvironmentPrefix = 'dart.library.'; | 369 const String _dartLibraryEnvironmentPrefix = 'dart.library.'; |
| OLD | NEW |