mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 15:46:27 +00:00

* The createHistogram(options) options weren't actually implemented * Add a new count property that tracks the number of samples * Adds BigInt options for relevant properties * Adds add(other) method for RecordableHistogram * Cleans up and expands tests * Eliminates unnecessary ELDHistogram native class * Improve/Simplify histogram transfer impl Signed-off-by: James M Snell <jasnell@gmail.com> perf_hooks: simplify Histogram constructor options Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/41153 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
87 lines
1.6 KiB
JavaScript
87 lines
1.6 KiB
JavaScript
'use strict';
|
|
const {
|
|
ReflectConstruct,
|
|
SafeMap,
|
|
Symbol,
|
|
} = primordials;
|
|
|
|
const {
|
|
codes: {
|
|
ERR_ILLEGAL_CONSTRUCTOR,
|
|
ERR_INVALID_THIS,
|
|
}
|
|
} = require('internal/errors');
|
|
|
|
const {
|
|
createELDHistogram,
|
|
} = internalBinding('performance');
|
|
|
|
const {
|
|
validateInteger,
|
|
validateObject,
|
|
} = require('internal/validators');
|
|
|
|
const {
|
|
Histogram,
|
|
kHandle,
|
|
kMap,
|
|
} = require('internal/histogram');
|
|
|
|
const {
|
|
makeTransferable,
|
|
} = require('internal/worker/js_transferable');
|
|
|
|
const kEnabled = Symbol('kEnabled');
|
|
|
|
class ELDHistogram extends Histogram {
|
|
constructor(i) {
|
|
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
|
}
|
|
|
|
/**
|
|
* @returns {boolean}
|
|
*/
|
|
enable() {
|
|
if (this[kEnabled] === undefined)
|
|
throw new ERR_INVALID_THIS('ELDHistogram');
|
|
if (this[kEnabled]) return false;
|
|
this[kEnabled] = true;
|
|
this[kHandle].start();
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @returns {boolean}
|
|
*/
|
|
disable() {
|
|
if (this[kEnabled] === undefined)
|
|
throw new ERR_INVALID_THIS('ELDHistogram');
|
|
if (!this[kEnabled]) return false;
|
|
this[kEnabled] = false;
|
|
this[kHandle].stop();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {{
|
|
* resolution : number
|
|
* }} [options]
|
|
* @returns {ELDHistogram}
|
|
*/
|
|
function monitorEventLoopDelay(options = {}) {
|
|
validateObject(options, 'options');
|
|
|
|
const { resolution = 10 } = options;
|
|
validateInteger(resolution, 'options.resolution', 1);
|
|
|
|
return makeTransferable(ReflectConstruct(
|
|
function() {
|
|
this[kEnabled] = false;
|
|
this[kHandle] = createELDHistogram(resolution);
|
|
this[kMap] = new SafeMap();
|
|
}, [], ELDHistogram));
|
|
}
|
|
|
|
module.exports = monitorEventLoopDelay;
|