mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 23:36:56 +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>
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const http2 = require('http2');
|
|
|
|
const { PerformanceObserver } = require('perf_hooks');
|
|
|
|
const server = http2.createServer();
|
|
|
|
server.on('stream', (stream, headers) => {
|
|
stream.respond({
|
|
'content-type': 'text/html',
|
|
':status': 200
|
|
});
|
|
switch (headers[':path']) {
|
|
case '/singleEnd':
|
|
stream.end('OK');
|
|
break;
|
|
case '/sequentialEnd':
|
|
stream.write('OK');
|
|
stream.end();
|
|
break;
|
|
case '/delayedEnd':
|
|
stream.write('OK', () => stream.end());
|
|
break;
|
|
}
|
|
});
|
|
|
|
function testRequest(path, targetFrameCount, callback) {
|
|
const obs = new PerformanceObserver(
|
|
common.mustCallAtLeast((list, observer) => {
|
|
const entry = list.getEntries()[0];
|
|
if (entry.name !== 'Http2Session') return;
|
|
if (entry.detail.type !== 'client') return;
|
|
assert.strictEqual(entry.detail.framesReceived, targetFrameCount);
|
|
observer.disconnect();
|
|
callback();
|
|
}));
|
|
obs.observe({ type: 'http2' });
|
|
const client =
|
|
http2.connect(`http://localhost:${server.address().port}`, () => {
|
|
const req = client.request({ ':path': path });
|
|
req.resume();
|
|
req.end();
|
|
req.on('end', () => client.close());
|
|
});
|
|
}
|
|
|
|
// SETTINGS => SETTINGS => HEADERS => DATA
|
|
const MIN_FRAME_COUNT = 4;
|
|
|
|
server.listen(0, () => {
|
|
testRequest('/singleEnd', MIN_FRAME_COUNT, () => {
|
|
testRequest('/sequentialEnd', MIN_FRAME_COUNT, () => {
|
|
testRequest('/delayedEnd', MIN_FRAME_COUNT + 1, () => {
|
|
server.close();
|
|
});
|
|
});
|
|
});
|
|
});
|