Created
December 2, 2015 18:52
-
-
Save natduca/f59ee78f997249e635b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tracing/tracing/base/task.html b/tracing/tracing/base/task.html | |
index bd876cb..6188bf7 100644 | |
--- a/tracing/tracing/base/task.html | |
+++ b/tracing/tracing/base/task.html | |
@@ -46,11 +46,14 @@ tr.exportTo('tr.b', function() { | |
} | |
Task.prototype = { | |
+ get name() { | |
+ return this.runCb_.name; | |
+ }, | |
+ | |
/* | |
* See constructor documentation on semantics of subtasks. | |
*/ | |
subTask: function(cb, thisArg) { | |
- if (cb instanceof Task) | |
this.subTasks_.push(cb); | |
else | |
this.subTasks_.push(new Task(cb, thisArg)); | |
@@ -94,6 +97,34 @@ tr.exportTo('tr.b', function() { | |
}, | |
/* | |
+ * ... | |
+ | |
+ // Note: timedAfter does not work when a task throws. This is because | |
+ // the task system doesn't support catching currently. At the time of | |
+ // writing, this is considered to be an acceptable tradeoff. | |
+ */ | |
+ timedAfter: function(cb, thisArg) { | |
+ if (this.afterTask_) | |
+ throw new Error('Has an after task already'); | |
+ var realTask; | |
+ if (cb instanceof Task) | |
+ realTask = cb; | |
+ else | |
+ realTask = new Task(cb, thisArg); | |
+ | |
+ // TODO errcheck that realTask.name is not undefiend; | |
+ | |
+ this.afterTask_ = new Task(function(task) { | |
+ timeBegin(realTask.name) | |
+ task.subTask(realTask, thisArg); | |
+ task.afterTask(function(cb) { | |
+ timeEnd(); | |
+ }) | |
+ }); | |
+ return this.afterTask_; | |
+ }, | |
+ | |
+ /* | |
* Adds a task after the chain of tasks. | |
*/ | |
enqueue: function(cb, thisArg) { | |
diff --git a/tracing/tracing/base/time_function.html b/tracing/tracing/base/time_function.html | |
index ab1e6f1..d4259d1 100644 | |
--- a/tracing/tracing/base/time_function.html | |
+++ b/tracing/tracing/base/time_function.html | |
@@ -1,3 +1,33 @@ | |
+/// notes to throw away | |
+ | |
+timeFunction() { | |
+ timeBegin(name); | |
+ try { | |
+ res = cb() | |
+ } catch(e) { | |
+ timeEnd | |
+ throw e; | |
+ } | |
+ | |
+ if (res instanceof Promise) | |
+ res.then(function(r) { | |
+ timeEnd(name); | |
+ return r; | |
+ }, function(err) { | |
+ timeEnd(name); | |
+ throw err; | |
+ }); | |
+ return; | |
+ } | |
+ | |
+ timeEnd(name); | |
+ return res; | |
+} | |
+ | |
+ | |
+ | |
+ | |
+ | |
<!DOCTYPE html> | |
<!-- | |
Copyright (c) 2014 The Chromium Authors. All rights reserved. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment