Bug 1724222 - Add profiler markers in DeferredTask, r=mconley.

Differential Revision: https://phabricator.services.mozilla.com/D121887
This commit is contained in:
Florian Quèze
2021-08-05 17:30:09 +00:00
parent 492b18bcec
commit 0d1d9e8505

View File

@@ -118,6 +118,16 @@ var DeferredTask = function(aTaskFn, aDelayMs, aIdleTimeoutMs) {
this._taskFn = aTaskFn;
this._delayMs = aDelayMs;
this._timeoutMs = aIdleTimeoutMs;
this._caller = new Error().stack.split("\n", 2)[1];
let markerString = `delay: ${aDelayMs}ms`;
if (aIdleTimeoutMs) {
markerString += `, idle timeout: ${aIdleTimeoutMs}`;
}
ChromeUtils.addProfilerMarker(
"DeferredTask",
{ captureStack: true },
markerString
);
};
DeferredTask.prototype = {
@@ -329,10 +339,17 @@ DeferredTask.prototype = {
* Executes the associated task and catches exceptions.
*/
async _runTask() {
let startTime = Cu.now();
try {
await this._taskFn();
} catch (ex) {
Cu.reportError(ex);
} finally {
ChromeUtils.addProfilerMarker(
"DeferredTask",
{ startTime },
this._caller
);
}
},
};