| 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 dart2js.common.tasks; | 5 library dart2js.common.tasks; |
| 6 | 6 |
| 7 import 'dart:developer' show | |
| 8 UserTag; | |
| 9 | |
| 10 import '../common.dart'; | 7 import '../common.dart'; |
| 11 import '../compiler.dart' show | 8 import '../compiler.dart' show |
| 12 Compiler; | 9 Compiler; |
| 13 import '../elements/elements.dart' show | 10 import '../elements/elements.dart' show |
| 14 Element; | 11 Element; |
| 15 | 12 |
| 16 typedef void DeferredAction(); | 13 typedef void DeferredAction(); |
| 17 | 14 |
| 18 class DeferredTask { | 15 class DeferredTask { |
| 19 final Element element; | 16 final Element element; |
| 20 final DeferredAction action; | 17 final DeferredAction action; |
| 21 | 18 |
| 22 DeferredTask(this.element, this.action); | 19 DeferredTask(this.element, this.action); |
| 23 } | 20 } |
| 24 | 21 |
| 25 class CompilerTask { | 22 class CompilerTask { |
| 26 final Compiler compiler; | 23 final Compiler compiler; |
| 27 final Stopwatch watch; | 24 final Stopwatch watch; |
| 28 UserTag profilerTag; | |
| 29 final Map<String, GenericTask> _subtasks = <String, GenericTask>{}; | 25 final Map<String, GenericTask> _subtasks = <String, GenericTask>{}; |
| 30 | 26 |
| 31 CompilerTask(Compiler compiler) | 27 CompilerTask(Compiler compiler) |
| 32 : this.compiler = compiler, | 28 : this.compiler = compiler, |
| 33 watch = (compiler.verbose) ? new Stopwatch() : null; | 29 watch = (compiler.verbose) ? new Stopwatch() : null; |
| 34 | 30 |
| 35 DiagnosticReporter get reporter => compiler.reporter; | 31 DiagnosticReporter get reporter => compiler.reporter; |
| 36 | 32 |
| 37 String get name => "Unknown task '${this.runtimeType}'"; | 33 String get name => "Unknown task '${this.runtimeType}'"; |
| 38 | 34 |
| 39 int get timing { | 35 int get timing { |
| 40 if (watch == null) return 0; | 36 if (watch == null) return 0; |
| 41 int total = watch.elapsedMilliseconds; | 37 int total = watch.elapsedMilliseconds; |
| 42 for (GenericTask subtask in _subtasks.values) { | 38 for (GenericTask subtask in _subtasks.values) { |
| 43 total += subtask.timing; | 39 total += subtask.timing; |
| 44 } | 40 } |
| 45 return total; | 41 return total; |
| 46 } | 42 } |
| 47 | 43 |
| 48 UserTag getProfilerTag() { | |
| 49 if (profilerTag == null) profilerTag = new UserTag(name); | |
| 50 return profilerTag; | |
| 51 } | |
| 52 | |
| 53 measure(action()) { | 44 measure(action()) { |
| 54 // In verbose mode when watch != null. | 45 // In verbose mode when watch != null. |
| 55 if (watch == null) return action(); | 46 if (watch == null) return action(); |
| 56 CompilerTask previous = compiler.measuredTask; | 47 CompilerTask previous = compiler.measuredTask; |
| 57 if (identical(this, previous)) return action(); | 48 if (identical(this, previous)) return action(); |
| 58 compiler.measuredTask = this; | 49 compiler.measuredTask = this; |
| 59 if (previous != null) previous.watch.stop(); | 50 if (previous != null) previous.watch.stop(); |
| 60 watch.start(); | 51 watch.start(); |
| 61 UserTag oldTag = getProfilerTag().makeCurrent(); | |
| 62 try { | 52 try { |
| 63 return action(); | 53 return action(); |
| 64 } finally { | 54 } finally { |
| 65 watch.stop(); | 55 watch.stop(); |
| 66 oldTag.makeCurrent(); | |
| 67 if (previous != null) previous.watch.start(); | 56 if (previous != null) previous.watch.start(); |
| 68 compiler.measuredTask = previous; | 57 compiler.measuredTask = previous; |
| 69 } | 58 } |
| 70 } | 59 } |
| 71 | 60 |
| 72 measureElement(Element element, action()) { | 61 measureElement(Element element, action()) { |
| 73 reporter.withCurrentElement(element, () => measure(action)); | 62 reporter.withCurrentElement(element, () => measure(action)); |
| 74 } | 63 } |
| 75 | 64 |
| 76 /// Measure the time spent in [action] (if in verbose mode) and accumulate it | 65 /// Measure the time spent in [action] (if in verbose mode) and accumulate it |
| (...skipping 12 matching lines...) Expand all Loading... |
| 89 | 78 |
| 90 int getSubtaskTime(String subtask) => _subtasks[subtask].timing; | 79 int getSubtaskTime(String subtask) => _subtasks[subtask].timing; |
| 91 } | 80 } |
| 92 | 81 |
| 93 class GenericTask extends CompilerTask { | 82 class GenericTask extends CompilerTask { |
| 94 final String name; | 83 final String name; |
| 95 | 84 |
| 96 GenericTask(this.name, Compiler compiler) | 85 GenericTask(this.name, Compiler compiler) |
| 97 : super(compiler); | 86 : super(compiler); |
| 98 } | 87 } |
| OLD | NEW |