mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
perf_hooks: introduce createHistogram
Adds a new `perf_hooks.createHistogram()` API for creating histogram instances that allow user recording. Makes Histogram instances cloneable via MessagePort. This allows, for instance, an event loop delay monitor to be running on the main thread while the histogram data can be monitored actively from a worker thread. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/37155 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
ce4798b555
commit
4a19cc8947
15 changed files with 781 additions and 320 deletions
|
@ -16,6 +16,7 @@ const {
|
|||
ObjectKeys,
|
||||
SafeSet,
|
||||
Symbol,
|
||||
TypeError,
|
||||
} = primordials;
|
||||
|
||||
const {
|
||||
|
@ -65,6 +66,7 @@ const {
|
|||
|
||||
const {
|
||||
Histogram,
|
||||
createHistogram,
|
||||
kHandle,
|
||||
} = require('internal/histogram');
|
||||
|
||||
|
@ -86,6 +88,7 @@ const kInsertEntry = Symbol('insert-entry');
|
|||
const kGetEntries = Symbol('get-entries');
|
||||
const kIndex = Symbol('index');
|
||||
const kMarks = Symbol('marks');
|
||||
const kEnabled = Symbol('kEnabled');
|
||||
|
||||
const observers = {};
|
||||
const observerableTypes = [
|
||||
|
@ -630,9 +633,26 @@ function sortedInsert(list, entry) {
|
|||
}
|
||||
|
||||
class ELDHistogram extends Histogram {
|
||||
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
||||
enable() { return this[kHandle].enable(); }
|
||||
disable() { return this[kHandle].disable(); }
|
||||
constructor(i) {
|
||||
if (!(i instanceof _ELDHistogram)) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
throw new TypeError('illegal constructor');
|
||||
}
|
||||
super(i);
|
||||
this[kEnabled] = false;
|
||||
}
|
||||
enable() {
|
||||
if (this[kEnabled]) return false;
|
||||
this[kEnabled] = true;
|
||||
this[kHandle].start();
|
||||
return true;
|
||||
}
|
||||
disable() {
|
||||
if (!this[kEnabled]) return false;
|
||||
this[kEnabled] = false;
|
||||
this[kHandle].stop();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function monitorEventLoopDelay(options = {}) {
|
||||
|
@ -651,7 +671,8 @@ function monitorEventLoopDelay(options = {}) {
|
|||
module.exports = {
|
||||
performance,
|
||||
PerformanceObserver,
|
||||
monitorEventLoopDelay
|
||||
monitorEventLoopDelay,
|
||||
createHistogram,
|
||||
};
|
||||
|
||||
ObjectDefineProperty(module.exports, 'constants', {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue