mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
`performance.nodeTiming.uvMetricsInfo` returns the libuv event loop metrics as numbers, which are only exact up to `Number.MAX_SAFE_INTEGER`. Add `uvMetricsInfoBigInt`, which returns the same metrics as bigints backed by `uint64_t` storage, carrying the full 64-bit range reported by libuv. A single native call fills both a `Float64Array` and a `BigUint64Array`, so `uvMetricsInfo` does not pay for bigint allocation and conversion. The new property is omitted from `toJSON()`, as `JSON.stringify()` cannot serialize bigints. Assisted-by: OpenCode Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66094 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
67 lines
2.3 KiB
JavaScript
67 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { performance } = require('perf_hooks');
|
|
const { isMainThread } = require('worker_threads');
|
|
|
|
const { nodeTiming } = performance;
|
|
assert.strictEqual(nodeTiming.name, 'node');
|
|
assert.strictEqual(nodeTiming.entryType, 'node');
|
|
|
|
assert.strictEqual(nodeTiming.startTime, 0);
|
|
|
|
// uvMetricsInfoBigInt holds bigint values, which JSON.stringify() cannot
|
|
// serialize, so it must not be part of the JSON representation, nor be copied
|
|
// along with the enumerable properties.
|
|
assert.strictEqual(typeof nodeTiming.uvMetricsInfoBigInt.loopCount, 'bigint');
|
|
assert.strictEqual(
|
|
Object.getOwnPropertyDescriptor(nodeTiming, 'uvMetricsInfoBigInt').enumerable,
|
|
false);
|
|
assert.strictEqual(
|
|
Object.hasOwn(JSON.parse(JSON.stringify(nodeTiming)), 'uvMetricsInfoBigInt'),
|
|
false);
|
|
assert.strictEqual(
|
|
Object.hasOwn(JSON.parse(JSON.stringify(performance)).nodeTiming,
|
|
'uvMetricsInfoBigInt'),
|
|
false);
|
|
{
|
|
const copy = { ...nodeTiming };
|
|
assert.strictEqual(Object.hasOwn(copy, 'uvMetricsInfoBigInt'), false);
|
|
assert.strictEqual(typeof JSON.stringify(copy), 'string');
|
|
}
|
|
const now = performance.now();
|
|
assert.ok(nodeTiming.duration >= now);
|
|
|
|
// Check that the nodeTiming milestone values are in the correct order and greater than 0.
|
|
const keys = ['nodeStart', 'v8Start', 'environment', 'bootstrapComplete'];
|
|
for (let idx = 0; idx < keys.length; idx++) {
|
|
if (idx === 0) {
|
|
assert.ok(nodeTiming[keys[idx]] >= 0);
|
|
continue;
|
|
}
|
|
assert.ok(nodeTiming[keys[idx]] > nodeTiming[keys[idx - 1]], `expect nodeTiming['${keys[idx]}'] > nodeTiming['${keys[idx - 1]}']`);
|
|
}
|
|
|
|
// loop milestones.
|
|
assert.strictEqual(nodeTiming.idleTime, 0);
|
|
if (isMainThread) {
|
|
// Main thread does not start loop until the first tick is finished.
|
|
assert.strictEqual(nodeTiming.loopStart, -1);
|
|
} else {
|
|
// Worker threads run the user script after loop is started.
|
|
assert.ok(nodeTiming.loopStart >= nodeTiming.bootstrapComplete);
|
|
}
|
|
assert.strictEqual(nodeTiming.loopExit, -1);
|
|
|
|
setTimeout(common.mustCall(() => {
|
|
assert.ok(nodeTiming.idleTime >= 0);
|
|
assert.ok(nodeTiming.idleTime + nodeTiming.loopExit <= nodeTiming.duration);
|
|
assert.ok(nodeTiming.loopStart >= nodeTiming.bootstrapComplete);
|
|
}, 1), 1);
|
|
|
|
// Can not be wrapped in common.mustCall().
|
|
process.on('exit', () => {
|
|
assert.ok(nodeTiming.loopExit > 0);
|
|
});
|