Bug 1838629 - Part 7: Inline nursery cell allocation method in Allocator.h r=sfink
[gecko.git] / toolkit / modules / ResponsivenessMonitor.sys.mjs
blob2437fbbd6c158f375308f0a2ef6776c57acfb3f4
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(
11     this,
12     this._intervalMS,
13     Ci.nsITimer.TYPE_REPEATING_SLACK
14   );
17 ResponsivenessMonitor.prototype = {
18   QueryInterface: ChromeUtils.generateQI(["nsINamed", "nsITimerCallback"]),
20   name: "ResponsivenessMonitor",
22   notify() {
23     let now = Date.now();
24     this._accumulatedDelay += Math.max(
25       0,
26       now - this._prevTimestamp - this._intervalMS
27     );
28     this._prevTimestamp = now;
29   },
31   abort() {
32     if (this._timer) {
33       this._timer.cancel();
34       this._timer = null;
35     }
36   },
38   finish() {
39     this.abort();
40     return this._accumulatedDelay;
41   },