mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

* Update the user timing implementation to conform to User Timing Level 3. * Reimplement user timing and timerify with pure JavaScript implementations * Simplify the C++ implementation for gc and http2 perf * Runtime deprecate additional perf entry properties in favor of the standard detail argument * Disable the `buffered` option on PerformanceObserver, all entries are queued and dispatched on setImmediate. Only entries with active observers are buffered. * This does remove the user timing and timerify trace events. Because the trace_events are still considered experimental, those can be removed without a deprecation cycle. They are removed to improve performance and reduce complexity. Old: `perf_hooks/usertiming.js n=100000: 92,378.01249733355` New: perf_hooks/usertiming.js n=100000: 270,393.5280638482` PR-URL: https://github.com/nodejs/node/pull/37136 Refs: https://github.com/nodejs/diagnostics/issues/464 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
85 lines
2.4 KiB
JavaScript
85 lines
2.4 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { performance } = require('perf_hooks');
|
|
|
|
if (!common.isMainThread)
|
|
common.skip('bootstrapping workers works differently');
|
|
|
|
assert(performance);
|
|
assert(performance.nodeTiming);
|
|
assert.strictEqual(typeof performance.timeOrigin, 'number');
|
|
// Use a fairly large epsilon value, since we can only guarantee that the node
|
|
// process started up in 15 seconds.
|
|
assert(Math.abs(performance.timeOrigin - Date.now()) < 15000);
|
|
|
|
const inited = performance.now();
|
|
assert(inited < 15000);
|
|
|
|
assert.strictEqual(performance.nodeTiming.name, 'node');
|
|
assert.strictEqual(performance.nodeTiming.entryType, 'node');
|
|
|
|
const delay = 250;
|
|
function checkNodeTiming(props) {
|
|
console.log(props);
|
|
|
|
for (const prop of Object.keys(props)) {
|
|
if (props[prop].around !== undefined) {
|
|
assert.strictEqual(typeof performance.nodeTiming[prop], 'number');
|
|
const delta = performance.nodeTiming[prop] - props[prop].around;
|
|
assert(
|
|
Math.abs(delta) < (props[prop].delay || delay),
|
|
`${prop}: ${Math.abs(delta)} >= ${props[prop].delay || delay}`
|
|
);
|
|
} else {
|
|
assert.strictEqual(performance.nodeTiming[prop], props[prop],
|
|
`mismatch for performance property ${prop}: ` +
|
|
`${performance.nodeTiming[prop]} vs ${props[prop]}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
checkNodeTiming({
|
|
name: 'node',
|
|
entryType: 'node',
|
|
startTime: 0,
|
|
duration: { around: performance.now() },
|
|
nodeStart: { around: 0 },
|
|
v8Start: { around: 0 },
|
|
bootstrapComplete: { around: inited, delay: 2500 },
|
|
environment: { around: 0 },
|
|
loopStart: -1,
|
|
loopExit: -1
|
|
});
|
|
|
|
setTimeout(() => {
|
|
checkNodeTiming({
|
|
name: 'node',
|
|
entryType: 'node',
|
|
startTime: 0,
|
|
duration: { around: performance.now() },
|
|
nodeStart: { around: 0 },
|
|
v8Start: { around: 0 },
|
|
bootstrapComplete: { around: inited, delay: 2500 },
|
|
environment: { around: 0 },
|
|
loopStart: { around: inited, delay: 2500 },
|
|
loopExit: -1
|
|
});
|
|
}, 1000);
|
|
|
|
process.on('exit', () => {
|
|
checkNodeTiming({
|
|
name: 'node',
|
|
entryType: 'node',
|
|
startTime: 0,
|
|
duration: { around: performance.now() },
|
|
nodeStart: { around: 0 },
|
|
v8Start: { around: 0 },
|
|
bootstrapComplete: { around: inited, delay: 2500 },
|
|
environment: { around: 0 },
|
|
loopStart: { around: inited, delay: 2500 },
|
|
loopExit: { around: performance.now() }
|
|
});
|
|
});
|