| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer.src.task.driver; | 5 library analyzer.src.task.driver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 523 |
| 524 StronglyConnectedComponent(this.nodes, this.containsCycle); | 524 StronglyConnectedComponent(this.nodes, this.containsCycle); |
| 525 } | 525 } |
| 526 | 526 |
| 527 /** | 527 /** |
| 528 * A description of a single analysis task that can be performed to advance | 528 * A description of a single analysis task that can be performed to advance |
| 529 * analysis. | 529 * analysis. |
| 530 */ | 530 */ |
| 531 class WorkItem { | 531 class WorkItem { |
| 532 /** | 532 /** |
| 533 * A table mapping the names of analysis tasks to the number of times each | |
| 534 * kind of task has been performed. | |
| 535 */ | |
| 536 static final Map<TaskDescriptor, int> countMap = | |
| 537 new HashMap<TaskDescriptor, int>(); | |
| 538 | |
| 539 /** | |
| 540 * A table mapping the names of analysis tasks to stopwatches used to compute | |
| 541 * how much time was spent between creating an item and creating (for | |
| 542 * performing) of each kind of task | |
| 543 */ | |
| 544 static final Map<TaskDescriptor, Stopwatch> stopwatchMap = | |
| 545 new HashMap<TaskDescriptor, Stopwatch>(); | |
| 546 | |
| 547 /** | |
| 548 * The context in which the task will be performed. | 533 * The context in which the task will be performed. |
| 549 */ | 534 */ |
| 550 final InternalAnalysisContext context; | 535 final InternalAnalysisContext context; |
| 551 | 536 |
| 552 /** | 537 /** |
| 553 * The target for which a task is to be performed. | 538 * The target for which a task is to be performed. |
| 554 */ | 539 */ |
| 555 final AnalysisTarget target; | 540 final AnalysisTarget target; |
| 556 | 541 |
| 557 /** | 542 /** |
| 558 * A description of the task to be performed. | 543 * A description of the task to be performed. |
| 559 */ | 544 */ |
| 560 final TaskDescriptor descriptor; | 545 final TaskDescriptor descriptor; |
| 561 | 546 |
| 562 /** | 547 /** |
| 563 * The [ResultDescriptor] which was led to this work item being spawned. | 548 * The [ResultDescriptor] which was led to this work item being spawned. |
| 564 */ | 549 */ |
| 565 final ResultDescriptor spawningResult; | 550 final ResultDescriptor spawningResult; |
| 566 | 551 |
| 567 /** | 552 /** |
| 568 * The current inputs computing stopwatch. | |
| 569 */ | |
| 570 Stopwatch stopwatch; | |
| 571 | |
| 572 /** | |
| 573 * An iterator used to iterate over the descriptors of the inputs to the task, | 553 * An iterator used to iterate over the descriptors of the inputs to the task, |
| 574 * or `null` if all of the inputs have been collected and the task can be | 554 * or `null` if all of the inputs have been collected and the task can be |
| 575 * created. | 555 * created. |
| 576 */ | 556 */ |
| 577 TaskInputBuilder builder; | 557 TaskInputBuilder builder; |
| 578 | 558 |
| 579 /** | 559 /** |
| 580 * The [TargetedResult]s outputs of this task depends on. | 560 * The [TargetedResult]s outputs of this task depends on. |
| 581 */ | 561 */ |
| 582 final HashSet<TargetedResult> inputTargetedResults = | 562 final HashSet<TargetedResult> inputTargetedResults = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 612 identical(target, AnalysisContextTarget.request) | 592 identical(target, AnalysisContextTarget.request) |
| 613 ? new AnalysisContextTarget(context) | 593 ? new AnalysisContextTarget(context) |
| 614 : target; | 594 : target; |
| 615 Map<String, TaskInput> inputDescriptors = | 595 Map<String, TaskInput> inputDescriptors = |
| 616 descriptor.createTaskInputs(actualTarget); | 596 descriptor.createTaskInputs(actualTarget); |
| 617 builder = new TopLevelTaskInputBuilder(inputDescriptors); | 597 builder = new TopLevelTaskInputBuilder(inputDescriptors); |
| 618 if (!builder.moveNext()) { | 598 if (!builder.moveNext()) { |
| 619 builder = null; | 599 builder = null; |
| 620 } | 600 } |
| 621 inputs = new HashMap<String, dynamic>(); | 601 inputs = new HashMap<String, dynamic>(); |
| 622 // Update performance counters. | |
| 623 { | |
| 624 stopwatch = stopwatchMap[descriptor]; | |
| 625 if (stopwatch == null) { | |
| 626 stopwatch = new Stopwatch(); | |
| 627 stopwatchMap[descriptor] = stopwatch; | |
| 628 } | |
| 629 stopwatch.start(); | |
| 630 } | |
| 631 { | |
| 632 int count = countMap[descriptor]; | |
| 633 countMap[descriptor] = count == null ? 1 : count + 1; | |
| 634 } | |
| 635 } | 602 } |
| 636 | 603 |
| 637 @override | 604 @override |
| 638 int get hashCode => | 605 int get hashCode => |
| 639 JenkinsSmiHash.hash2(descriptor.hashCode, target.hashCode); | 606 JenkinsSmiHash.hash2(descriptor.hashCode, target.hashCode); |
| 640 | 607 |
| 641 @override | 608 @override |
| 642 bool operator ==(other) { | 609 bool operator ==(other) { |
| 643 if (other is WorkItem) { | 610 if (other is WorkItem) { |
| 644 return this.descriptor == other.descriptor && this.target == other.target; | 611 return this.descriptor == other.descriptor && this.target == other.target; |
| 645 } else { | 612 } else { |
| 646 return false; | 613 return false; |
| 647 } | 614 } |
| 648 } | 615 } |
| 649 | 616 |
| 650 /** | 617 /** |
| 651 * Build the task represented by this work item. | 618 * Build the task represented by this work item. |
| 652 */ | 619 */ |
| 653 AnalysisTask buildTask() { | 620 AnalysisTask buildTask() { |
| 654 stopwatch.stop(); | |
| 655 if (builder != null) { | 621 if (builder != null) { |
| 656 throw new StateError("some inputs have not been computed"); | 622 throw new StateError("some inputs have not been computed"); |
| 657 } | 623 } |
| 658 AnalysisTask task = descriptor.createTask(context, target, inputs); | 624 AnalysisTask task = descriptor.createTask(context, target, inputs); |
| 659 task.dependencyCycle = dependencyCycle; | 625 task.dependencyCycle = dependencyCycle; |
| 660 return task; | 626 return task; |
| 661 } | 627 } |
| 662 | 628 |
| 663 /** | 629 /** |
| 664 * Gather all of the inputs needed to perform the task. | 630 * Gather all of the inputs needed to perform the task. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 final TaskManager taskManager; | 775 final TaskManager taskManager; |
| 810 | 776 |
| 811 _WorkOrderDependencyWalker(this.taskManager, WorkItem startingNode) | 777 _WorkOrderDependencyWalker(this.taskManager, WorkItem startingNode) |
| 812 : super(startingNode); | 778 : super(startingNode); |
| 813 | 779 |
| 814 @override | 780 @override |
| 815 WorkItem getNextInput(WorkItem node, List<WorkItem> skipInputs) { | 781 WorkItem getNextInput(WorkItem node, List<WorkItem> skipInputs) { |
| 816 return node.gatherInputs(taskManager, skipInputs); | 782 return node.gatherInputs(taskManager, skipInputs); |
| 817 } | 783 } |
| 818 } | 784 } |
| OLD | NEW |