2021-01-29 00:34:27 +00:00
|
|
|
'use strict';
|
|
|
|
const {
|
2021-12-12 00:59:48 +00:00
|
|
|
ReflectConstruct,
|
|
|
|
SafeMap,
|
2021-01-29 00:34:27 +00:00
|
|
|
Symbol,
|
|
|
|
} = primordials;
|
|
|
|
|
2021-07-28 01:41:18 +00:00
|
|
|
const {
|
|
|
|
codes: {
|
|
|
|
ERR_ILLEGAL_CONSTRUCTOR,
|
2021-12-12 00:59:48 +00:00
|
|
|
ERR_INVALID_THIS,
|
2023-02-20 00:59:21 +00:00
|
|
|
},
|
2021-07-28 01:41:18 +00:00
|
|
|
} = require('internal/errors');
|
|
|
|
|
2021-01-29 00:34:27 +00:00
|
|
|
const {
|
2021-12-12 00:59:48 +00:00
|
|
|
createELDHistogram,
|
2021-01-29 00:34:27 +00:00
|
|
|
} = internalBinding('performance');
|
|
|
|
|
|
|
|
const {
|
|
|
|
validateInteger,
|
|
|
|
validateObject,
|
|
|
|
} = require('internal/validators');
|
|
|
|
|
|
|
|
const {
|
|
|
|
Histogram,
|
|
|
|
kHandle,
|
2021-12-12 00:59:48 +00:00
|
|
|
kMap,
|
2021-01-29 00:34:27 +00:00
|
|
|
} = require('internal/histogram');
|
|
|
|
|
2022-05-21 09:53:52 +00:00
|
|
|
const {
|
|
|
|
kEmptyObject,
|
|
|
|
} = require('internal/util');
|
|
|
|
|
2021-12-12 00:59:48 +00:00
|
|
|
const {
|
2023-07-07 17:00:00 +00:00
|
|
|
markTransferMode,
|
2021-12-12 00:59:48 +00:00
|
|
|
} = require('internal/worker/js_transferable');
|
|
|
|
|
2021-01-29 00:34:27 +00:00
|
|
|
const kEnabled = Symbol('kEnabled');
|
|
|
|
|
|
|
|
class ELDHistogram extends Histogram {
|
|
|
|
constructor(i) {
|
2021-12-12 00:59:48 +00:00
|
|
|
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
2021-01-29 00:34:27 +00:00
|
|
|
}
|
2021-12-12 00:59:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2021-01-29 00:34:27 +00:00
|
|
|
enable() {
|
2021-12-12 00:59:48 +00:00
|
|
|
if (this[kEnabled] === undefined)
|
|
|
|
throw new ERR_INVALID_THIS('ELDHistogram');
|
2021-01-29 00:34:27 +00:00
|
|
|
if (this[kEnabled]) return false;
|
|
|
|
this[kEnabled] = true;
|
|
|
|
this[kHandle].start();
|
|
|
|
return true;
|
|
|
|
}
|
2021-12-12 00:59:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2021-01-29 00:34:27 +00:00
|
|
|
disable() {
|
2021-12-12 00:59:48 +00:00
|
|
|
if (this[kEnabled] === undefined)
|
|
|
|
throw new ERR_INVALID_THIS('ELDHistogram');
|
2021-01-29 00:34:27 +00:00
|
|
|
if (!this[kEnabled]) return false;
|
|
|
|
this[kEnabled] = false;
|
|
|
|
this[kHandle].stop();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-12 00:59:48 +00:00
|
|
|
/**
|
|
|
|
* @param {{
|
|
|
|
* resolution : number
|
|
|
|
* }} [options]
|
|
|
|
* @returns {ELDHistogram}
|
|
|
|
*/
|
2022-05-21 09:53:52 +00:00
|
|
|
function monitorEventLoopDelay(options = kEmptyObject) {
|
2021-01-29 00:34:27 +00:00
|
|
|
validateObject(options, 'options');
|
|
|
|
|
|
|
|
const { resolution = 10 } = options;
|
|
|
|
validateInteger(resolution, 'options.resolution', 1);
|
|
|
|
|
2023-07-07 17:00:00 +00:00
|
|
|
return ReflectConstruct(
|
2021-12-12 00:59:48 +00:00
|
|
|
function() {
|
2023-07-07 17:00:00 +00:00
|
|
|
markTransferMode(this, true, false);
|
2021-12-12 00:59:48 +00:00
|
|
|
this[kEnabled] = false;
|
|
|
|
this[kHandle] = createELDHistogram(resolution);
|
|
|
|
this[kMap] = new SafeMap();
|
2023-07-07 17:00:00 +00:00
|
|
|
}, [], ELDHistogram);
|
2021-01-29 00:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = monitorEventLoopDelay;
|