mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
acaa58e602
PR-URL: https://github.com/nodejs/node/pull/36630 Refs: https://github.com/nodejs/node/pull/32329 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
Symbol,
|
|
Date,
|
|
} = primordials;
|
|
|
|
const { setUnrefTimeout } = require('internal/timers');
|
|
const { PerformanceEntry, notify } = internalBinding('performance');
|
|
|
|
let utcCache;
|
|
|
|
function utcDate() {
|
|
if (!utcCache) cache();
|
|
return utcCache;
|
|
}
|
|
|
|
function cache() {
|
|
const d = new Date();
|
|
utcCache = d.toUTCString();
|
|
setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
|
|
}
|
|
|
|
function resetCache() {
|
|
utcCache = undefined;
|
|
}
|
|
|
|
class HttpRequestTiming extends PerformanceEntry {
|
|
constructor(statistics) {
|
|
super();
|
|
this.name = 'HttpRequest';
|
|
this.entryType = 'http';
|
|
const startTime = statistics.startTime;
|
|
const diff = process.hrtime(startTime);
|
|
this.duration = diff[0] * 1000 + diff[1] / 1e6;
|
|
this.startTime = startTime[0] * 1000 + startTime[1] / 1e6;
|
|
}
|
|
}
|
|
|
|
function emitStatistics(statistics) {
|
|
notify('http', new HttpRequestTiming(statistics));
|
|
}
|
|
|
|
module.exports = {
|
|
kOutHeaders: Symbol('kOutHeaders'),
|
|
kNeedDrain: Symbol('kNeedDrain'),
|
|
utcDate,
|
|
emitStatistics
|
|
};
|