1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 export function ResponsivenessMonitor(intervalMS = 100) {
6 this._intervalMS = intervalMS;
7 this._prevTimestamp = Date.now();
8 this._accumulatedDelay = 0;
9 this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
10 this._timer.initWithCallback(
13 Ci.nsITimer.TYPE_REPEATING_SLACK
17 ResponsivenessMonitor.prototype = {
18 QueryInterface: ChromeUtils.generateQI(["nsINamed", "nsITimerCallback"]),
20 name: "ResponsivenessMonitor",
24 this._accumulatedDelay += Math.max(
26 now - this._prevTimestamp - this._intervalMS
28 this._prevTimestamp = now;
40 return this._accumulatedDelay;