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

Unified Diff: pkg/compiler/lib/src/common/tasks.dart

Issue 1362953002: dart2js: Measure time of individual optimization passes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add a comment Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/apiimpl.dart ('k') | pkg/compiler/lib/src/compiler.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
« no previous file with comments | « pkg/compiler/lib/src/apiimpl.dart ('k') | pkg/compiler/lib/src/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698