mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 10:42:18 +00:00

PR-URL: https://github.com/nodejs/node/pull/36194 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
Symbol,
|
|
Date,
|
|
DatePrototypeGetMilliseconds,
|
|
DatePrototypeToUTCString,
|
|
} = 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 = DatePrototypeToUTCString(d);
|
|
setUnrefTimeout(resetCache, 1000 - DatePrototypeGetMilliseconds(d));
|
|
}
|
|
|
|
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
|
|
};
|