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

Side by Side Diff: pkg/compiler/lib/src/apiimpl.dart

Issue 1454373002: Use Zone to correctly measure async operations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@_temporary_fletch_patches
Patch Set: Address Florian's comments Created 4 years, 11 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/compiler/lib/src/common/tasks.dart » ('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) 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' show 12 import 'package:package_config/src/packages_impl.dart' show
13 MapPackages, 13 MapPackages,
14 NonFilePackagesDirectoryPackages; 14 NonFilePackagesDirectoryPackages;
15 import 'package:package_config/src/util.dart' show 15 import 'package:package_config/src/util.dart' show
16 checkValidPackageUri; 16 checkValidPackageUri;
17 17
18 import '../compiler_new.dart' as api; 18 import '../compiler_new.dart' as api;
19 import 'commandline_options.dart'; 19 import 'commandline_options.dart';
20 import 'common.dart'; 20 import 'common.dart';
21 import 'common/tasks.dart' show 21 import 'common/tasks.dart' show
22 GenericTask; 22 GenericTask,
23 Measurer;
23 import 'common/backend_api.dart' show 24 import 'common/backend_api.dart' show
24 Backend; 25 Backend;
25 import 'compiler.dart'; 26 import 'compiler.dart';
26 import 'diagnostics/diagnostic_listener.dart' show 27 import 'diagnostics/diagnostic_listener.dart' show
27 DiagnosticOptions; 28 DiagnosticOptions;
28 import 'diagnostics/messages.dart' show 29 import 'diagnostics/messages.dart' show
29 Message; 30 Message;
30 import 'elements/elements.dart' as elements; 31 import 'elements/elements.dart' as elements;
31 import 'io/source_file.dart'; 32 import 'io/source_file.dart';
32 import 'platform_configuration.dart' as platform_configuration; 33 import 'platform_configuration.dart' as platform_configuration;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 node, 405 node,
405 MessageKind.LIBRARY_NOT_FOUND, 406 MessageKind.LIBRARY_NOT_FOUND,
406 {'resolvedUri': uri}); 407 {'resolvedUri': uri});
407 return null; 408 return null;
408 }); 409 });
409 } 410 }
410 411
411 Future<elements.LibraryElement> analyzeUri( 412 Future<elements.LibraryElement> analyzeUri(
412 Uri uri, 413 Uri uri,
413 {bool skipLibraryWithPartOfTag: true}) { 414 {bool skipLibraryWithPartOfTag: true}) {
414 List<Future> setupFutures = new List<Future>(); 415 return new Future(() => (sdkLibraries == null) ? setupSdk() : null)
415 if (sdkLibraries == null) { 416 .then((_) => packages == null ? setupPackages(uri) : null)
416 setupFutures.add(setupSdk()); 417 .then((_) => super.analyzeUri(uri));
417 }
418 if (packages == null) {
419 setupFutures.add(setupPackages(uri));
420 }
421 return Future.wait(setupFutures).then((_) => super.analyzeUri(uri));
422 } 418 }
423 419
424 Future setupPackages(Uri uri) { 420 Future setupPackages(Uri uri) {
425 if (packageRoot != null) { 421 if (packageRoot != null) {
426 // Use "non-file" packages because the file version requires a [Directory] 422 // Use "non-file" packages because the file version requires a [Directory]
427 // and we can't depend on 'dart:io' classes. 423 // and we can't depend on 'dart:io' classes.
428 packages = new NonFilePackagesDirectoryPackages(packageRoot); 424 packages = new NonFilePackagesDirectoryPackages(packageRoot);
429 } else if (packageConfig != null) { 425 } else if (packageConfig != null) {
430 return callUserProvider(packageConfig).then((packageConfigContents) { 426 return callUserProvider(packageConfig).then((packageConfigContents) {
431 if (packageConfigContents is String) { 427 if (packageConfigContents is String) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 sdkLibraries = mapping; 462 sdkLibraries = mapping;
467 }); 463 });
468 } else { 464 } else {
469 // The incremental compiler sets up the sdk before run. 465 // The incremental compiler sets up the sdk before run.
470 // Therefore this will be called a second time. 466 // Therefore this will be called a second time.
471 return new Future.value(null); 467 return new Future.value(null);
472 } 468 }
473 } 469 }
474 470
475 Future<bool> run(Uri uri) { 471 Future<bool> run(Uri uri) {
476 log('Using platform configuration at ${platformConfigUri}'); 472 Duration setupDuration = measurer.wallClock.elapsed;
473 return selfTask.measureSubtask("CompilerImpl.run", () {
474 log('Using platform configuration at ${platformConfigUri}');
477 475
478 return Future.wait([setupSdk(), setupPackages(uri)]).then((_) { 476 return setupSdk().then((_) => setupPackages(uri)).then((_) {
479 assert(sdkLibraries != null); 477 assert(sdkLibraries != null);
480 assert(packages != null); 478 assert(packages != null);
481 479 return super.run(uri);
482 return super.run(uri).then((bool success) { 480 }).then((bool success) {
483 int cumulated = 0; 481 StringBuffer timings = new StringBuffer();
482 timings.writeln("Timings:");
483 Duration totalDuration = measurer.wallClock.elapsed;
484 Duration asyncDuration = measurer.asyncWallClock.elapsed;
485 Duration cumulatedDuration = Duration.ZERO;
484 for (final task in tasks) { 486 for (final task in tasks) {
485 int elapsed = task.timing; 487 String running = task.isRunning ? "*" : "";
486 if (elapsed != 0) { 488 Duration duration = task.duration;
487 cumulated += elapsed; 489 if (duration != Duration.ZERO) {
488 log('${task.name} took ${elapsed}msec'); 490 cumulatedDuration += duration;
491 timings.writeln(
492 ' $running${task.name} took'
493 ' ${duration.inMilliseconds}msec');
489 for (String subtask in task.subtasks) { 494 for (String subtask in task.subtasks) {
490 int subtime = task.getSubtaskTime(subtask); 495 int subtime = task.getSubtaskTime(subtask);
491 log('${task.name} > $subtask took ${subtime}msec'); 496 String running = task.getSubtaskIsRunning(subtask) ? "*" : "";
497 timings.writeln(
498 ' $running${task.name} > $subtask took ${subtime}msec');
492 } 499 }
493 } 500 }
494 } 501 }
495 int total = totalCompileTime.elapsedMilliseconds; 502 Duration unaccountedDuration =
496 log('Total compile-time ${total}msec;' 503 totalDuration - cumulatedDuration - setupDuration - asyncDuration;
497 ' unaccounted ${total - cumulated}msec'); 504 double percent = unaccountedDuration.inMilliseconds * 100
505 / totalDuration.inMilliseconds;
506 timings.write(
507 ' Total compile-time ${totalDuration.inMilliseconds}msec;'
508 ' setup ${setupDuration.inMilliseconds}msec;'
509 ' async ${asyncDuration.inMilliseconds}msec;'
510 ' unaccounted ${unaccountedDuration.inMilliseconds}msec'
511 ' (${percent.toStringAsFixed(2)}%)');
512 log("$timings");
498 return success; 513 return success;
499 }); 514 });
500 }); 515 });
501 } 516 }
502 517
503 void reportDiagnostic(DiagnosticMessage message, 518 void reportDiagnostic(DiagnosticMessage message,
504 List<DiagnosticMessage> infos, 519 List<DiagnosticMessage> infos,
505 api.Diagnostic kind) { 520 api.Diagnostic kind) {
506 _reportDiagnosticMessage(message, kind); 521 _reportDiagnosticMessage(message, kind);
507 for (DiagnosticMessage info in infos) { 522 for (DiagnosticMessage info in infos) {
(...skipping 28 matching lines...) Expand all
536 }); 551 });
537 } catch (ex, s) { 552 } catch (ex, s) {
538 diagnoseCrashInUserCode( 553 diagnoseCrashInUserCode(
539 'Uncaught exception in diagnostic handler', ex, s); 554 'Uncaught exception in diagnostic handler', ex, s);
540 rethrow; 555 rethrow;
541 } 556 }
542 } 557 }
543 558
544 Future callUserProvider(Uri uri) { 559 Future callUserProvider(Uri uri) {
545 try { 560 try {
546 return userProviderTask.measure(() => provider.readFromUri(uri)); 561 return userProviderTask.measureIo(() => provider.readFromUri(uri));
547 } catch (ex, s) { 562 } catch (ex, s) {
548 diagnoseCrashInUserCode('Uncaught exception in input provider', ex, s); 563 diagnoseCrashInUserCode('Uncaught exception in input provider', ex, s);
549 rethrow; 564 rethrow;
550 } 565 }
551 } 566 }
552 567
553 Future<Packages> callUserPackagesDiscovery(Uri uri) { 568 Future<Packages> callUserPackagesDiscovery(Uri uri) {
554 try { 569 try {
555 return userPackagesDiscoveryTask.measure( 570 return userPackagesDiscoveryTask.measureIo(
556 () => packagesDiscoveryProvider(uri)); 571 () => packagesDiscoveryProvider(uri));
557 } catch (ex, s) { 572 } catch (ex, s) {
558 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s); 573 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s);
559 rethrow; 574 rethrow;
560 } 575 }
561 } 576 }
562 577
563 fromEnvironment(String name) => environment[name]; 578 fromEnvironment(String name) => environment[name];
564 579
565 Uri lookupLibraryUri(String libraryName) { 580 Uri lookupLibraryUri(String libraryName) {
566 assert(invariant(NO_LOCATION_SPANNABLE, 581 assert(invariant(NO_LOCATION_SPANNABLE,
567 sdkLibraries != null, message: "setupSdk() has not been run")); 582 sdkLibraries != null, message: "setupSdk() has not been run"));
568 return sdkLibraries[libraryName]; 583 return sdkLibraries[libraryName];
569 } 584 }
570 585
571 Uri resolvePatchUri(String libraryName) { 586 Uri resolvePatchUri(String libraryName) {
572 return backend.resolvePatchUri(libraryName, platformConfigUri); 587 return backend.resolvePatchUri(libraryName, platformConfigUri);
573 } 588 }
574 } 589 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/common/tasks.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698