| Index: pkg/compiler/lib/src/common/tasks.dart
|
| diff --git a/pkg/compiler/lib/src/common/tasks.dart b/pkg/compiler/lib/src/common/tasks.dart
|
| index 1cc39025be698e09f97b04ce514f482553f9aa50..32966df50b3fbdd936ed8d9df26cd518ff3eba15 100644
|
| --- a/pkg/compiler/lib/src/common/tasks.dart
|
| +++ b/pkg/compiler/lib/src/common/tasks.dart
|
| @@ -24,15 +24,22 @@ class CompilerTask {
|
| final Compiler compiler;
|
| final Stopwatch watch;
|
| UserTag profilerTag;
|
| + final Map<String, GenericTask> _subtasks = <String, GenericTask>{};
|
|
|
| CompilerTask(Compiler compiler)
|
| : this.compiler = compiler,
|
| watch = (compiler.verbose) ? new Stopwatch() : null;
|
|
|
| String get name => "Unknown task '${this.runtimeType}'";
|
| - int get timing => (watch != null) ? watch.elapsedMilliseconds : 0;
|
|
|
| - int get timingMicroseconds => (watch != null) ? watch.elapsedMicroseconds : 0;
|
| + int get timing {
|
| + if (watch == null) return 0;
|
| + int total = watch.elapsedMilliseconds;
|
| + for (GenericTask subtask in _subtasks.values) {
|
| + total += subtask.timing;
|
| + }
|
| + return total;
|
| + }
|
|
|
| UserTag getProfilerTag() {
|
| if (profilerTag == null) profilerTag = new UserTag(name);
|
| @@ -61,6 +68,22 @@ class CompilerTask {
|
| measureElement(Element element, action()) {
|
| compiler.withCurrentElement(element, () => measure(action));
|
| }
|
| +
|
| + /// Measure the time spent in [action] (if in verbose mode) and accumulate it
|
| + /// under a subtask with the given name.
|
| + measureSubtask(String name, action()) {
|
| + if (watch == null) return action();
|
| + // Use a nested CompilerTask for the measurement to ensure nested [measure]
|
| + // calls work correctly. The subtasks will never themselves have nested
|
| + // subtasks because they are not accessible outside.
|
| + GenericTask subtask = _subtasks.putIfAbsent(name,
|
| + () => new GenericTask(name, compiler));
|
| + return subtask.measure(action);
|
| + }
|
| +
|
| + Iterable<String> get subtasks => _subtasks.keys;
|
| +
|
| + int getSubtaskTime(String subtask) => _subtasks[subtask].timing;
|
| }
|
|
|
| class GenericTask extends CompilerTask {
|
|
|