mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
f3eb224c83
* 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>
51 lines
1.0 KiB
JavaScript
51 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
Symbol,
|
|
Date,
|
|
DatePrototypeGetMilliseconds,
|
|
DatePrototypeToUTCString,
|
|
} = primordials;
|
|
|
|
const { setUnrefTimeout } = require('internal/timers');
|
|
|
|
const { InternalPerformanceEntry } = require('internal/perf/perf');
|
|
const { enqueue } = require('internal/perf/observe');
|
|
|
|
let utcCache;
|
|
|
|
function utcDate() {
|
|
if (!utcCache) cache();
|
|
return utcCache;
|
|
}
|
|
|
|
function cache() {
|
|
const d = new Date();
|
|
utcCache = DatePrototypeToUTCString(d);
|
|
setUnrefTimeout(resetCache, 1000 - DatePrototypeGetMilliseconds(d));
|
|
}
|
|
|
|
function resetCache() {
|
|
utcCache = undefined;
|
|
}
|
|
|
|
function emitStatistics(statistics) {
|
|
const startTime = statistics.startTime;
|
|
const diff = process.hrtime(startTime);
|
|
const entry = new InternalPerformanceEntry(
|
|
'HttpRequest',
|
|
'http',
|
|
startTime[0] * 1000 + startTime[1] / 1e6,
|
|
diff[0] * 1000 + diff[1] / 1e6,
|
|
undefined,
|
|
);
|
|
enqueue(entry);
|
|
}
|
|
|
|
module.exports = {
|
|
kOutHeaders: Symbol('kOutHeaders'),
|
|
kNeedDrain: Symbol('kNeedDrain'),
|
|
utcDate,
|
|
emitStatistics
|
|
};
|