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

Unified Diff: pkg/compiler/lib/src/compiler.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: Created 5 years, 1 month 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') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/compiler.dart
diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart
index 950b4258588442ed79315f5d1c4bb4e528c6c231..36ceefa63aa824407a0571070e5d24910e169a43 100644
--- a/pkg/compiler/lib/src/compiler.dart
+++ b/pkg/compiler/lib/src/compiler.dart
@@ -2207,21 +2207,67 @@ class CompilerTask {
int get timingMicroseconds => (watch != null) ? watch.elapsedMicroseconds : 0;
- measure(action()) {
- // In verbose mode when watch != null.
- if (watch == null) return action();
+ measure(action()) => watch == null ? action() : measureZoned(action);
Johnni Winther 2015/11/19 10:02:18 Add doc
+
+ CompilerTask start() {
Johnni Winther 2015/11/19 10:02:18 Add doc
CompilerTask previous = compiler.measuredTask;
- if (identical(this, previous)) return action();
compiler.measuredTask = this;
if (previous != null) previous.watch.stop();
watch.start();
- try {
- return action();
- } finally {
- watch.stop();
- if (previous != null) previous.watch.start();
- compiler.measuredTask = previous;
+ return previous;
+ }
+
+ void stop(CompilerTask previous) {
Johnni Winther 2015/11/19 10:02:18 Add doc
+ watch.stop();
+ if (previous != null) previous.watch.start();
+ compiler.measuredTask = previous;
+ }
+
+ measureZoned(action()) {
Johnni Winther 2015/11/19 10:02:18 Add doc.
+ assert(watch != null);
+ if (identical(this, compiler.measuredTask)) return action();
+
+ run(Zone self, ZoneDelegate parent, Zone zone, f()) {
+ CompilerTask previous = start();
+ try {
+ return f();
+ } finally {
+ stop(previous);
+ }
}
+
+ runUnary(Zone self, ZoneDelegate parent, Zone zone, f(arg), arg) {
+ CompilerTask previous = start();
+ try {
+ return f(arg);
+ } finally {
+ stop(previous);
+ }
+ }
+
+ runBinary(Zone self, ZoneDelegate parent, Zone zone, f(a1, a2), a1, a2) {
+ CompilerTask previous = start();
+ try {
+ return f(a1, a2);
+ } finally {
+ stop(previous);
+ }
+ }
+
+ return runZoned(
+ action, zoneSpecification: new ZoneSpecification(
+ run: run, runUnary: runUnary, runBinary: runBinary));
+ }
+
+ measureIo(action()) => watch == null ? action() : measureIoHelper(action);
Johnni Winther 2015/11/19 10:02:18 Add doc
+
+ Future measureIoHelper(Future action()) {
+ assert(watch != null);
+ if (identical(this, compiler.measuredTask)) return action();
+ CompilerTask previous = start();
+ return measure(action).whenComplete(() {
+ stop(previous);
+ });
}
measureElement(Element element, action()) {
« no previous file with comments | « pkg/compiler/lib/src/apiimpl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698