node/lib/internal/perf/nodetiming.js
Rafael Gonzaga 9a275e15c3
src,lib: add performance.uvMetricsInfo
This commit exposes a new API to the perf_hooks.performance
module. This wraps uv_metrics_info into
performance.uvMetricsInfo() function.

PR-URL: https://github.com/nodejs/node/pull/54413
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2024-08-30 14:22:28 +00:00

168 lines
3.6 KiB
JavaScript

'use strict';
const {
ObjectDefineProperties,
ObjectSetPrototypeOf,
} = primordials;
const { PerformanceEntry } = require('internal/perf/performance_entry');
const {
now,
getMilestoneTimestamp,
} = require('internal/perf/utils');
const {
customInspectSymbol: kInspect,
} = require('internal/util');
const { inspect } = require('util');
const {
constants: {
NODE_PERFORMANCE_MILESTONE_NODE_START,
NODE_PERFORMANCE_MILESTONE_V8_START,
NODE_PERFORMANCE_MILESTONE_LOOP_START,
NODE_PERFORMANCE_MILESTONE_LOOP_EXIT,
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE,
NODE_PERFORMANCE_MILESTONE_ENVIRONMENT,
},
loopIdleTime,
uvMetricsInfo,
} = internalBinding('performance');
class PerformanceNodeTiming {
constructor() {
ObjectDefineProperties(this, {
name: {
__proto__: null,
enumerable: true,
configurable: true,
value: 'node',
},
entryType: {
__proto__: null,
enumerable: true,
configurable: true,
value: 'node',
},
startTime: {
__proto__: null,
enumerable: true,
configurable: true,
value: 0,
},
duration: {
__proto__: null,
enumerable: true,
configurable: true,
get: now,
},
nodeStart: {
__proto__: null,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
},
},
v8Start: {
__proto__: null,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
},
},
environment: {
__proto__: null,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
},
},
loopStart: {
__proto__: null,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
},
},
loopExit: {
__proto__: null,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
},
},
bootstrapComplete: {
__proto__: null,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
},
},
idleTime: {
__proto__: null,
enumerable: true,
configurable: true,
get: loopIdleTime,
},
uvMetricsInfo: {
__proto__: null,
enumerable: true,
configurable: true,
get: uvMetricsInfo,
},
});
}
[kInspect](depth, options) {
if (depth < 0) return this;
const opts = {
...options,
depth: options.depth == null ? null : options.depth - 1,
};
return `PerformanceNodeTiming ${inspect(this.toJSON(), opts)}`;
}
toJSON() {
return {
name: 'node',
entryType: 'node',
startTime: this.startTime,
duration: this.duration,
nodeStart: this.nodeStart,
v8Start: this.v8Start,
bootstrapComplete: this.bootstrapComplete,
environment: this.environment,
loopStart: this.loopStart,
loopExit: this.loopExit,
idleTime: this.idleTime,
};
}
}
ObjectSetPrototypeOf(
PerformanceNodeTiming.prototype,
PerformanceEntry.prototype);
module.exports = new PerformanceNodeTiming();