2017-03-06 03:13:09 +01:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-30 16:55:29 +01:00
|
|
|
const {
|
|
|
|
Symbol,
|
|
|
|
} = primordials;
|
|
|
|
|
2017-12-21 03:50:19 +01:00
|
|
|
const { setUnrefTimeout } = require('internal/timers');
|
2019-06-30 22:37:18 +02:00
|
|
|
const { PerformanceEntry, notify } = internalBinding('performance');
|
2016-10-17 20:38:52 +02:00
|
|
|
|
2019-11-12 16:46:28 +01:00
|
|
|
let nowCache;
|
|
|
|
let utcCache;
|
2018-08-23 16:46:07 +02:00
|
|
|
|
|
|
|
function nowDate() {
|
|
|
|
if (!nowCache) cache();
|
|
|
|
return nowCache;
|
|
|
|
}
|
|
|
|
|
2016-10-17 20:38:52 +02:00
|
|
|
function utcDate() {
|
2018-08-23 16:46:07 +02:00
|
|
|
if (!utcCache) cache();
|
|
|
|
return utcCache;
|
|
|
|
}
|
2017-12-21 03:50:19 +01:00
|
|
|
|
2018-08-23 16:46:07 +02:00
|
|
|
function cache() {
|
|
|
|
const d = new Date();
|
|
|
|
nowCache = d.valueOf();
|
|
|
|
utcCache = d.toUTCString();
|
|
|
|
setUnrefTimeout(resetCache, 1000 - d.getMilliseconds());
|
2016-10-17 20:38:52 +02:00
|
|
|
}
|
2017-12-21 03:50:19 +01:00
|
|
|
|
|
|
|
function resetCache() {
|
2018-08-23 16:46:07 +02:00
|
|
|
nowCache = undefined;
|
|
|
|
utcCache = undefined;
|
2017-12-21 03:50:19 +01:00
|
|
|
}
|
2016-10-17 20:38:52 +02:00
|
|
|
|
2019-06-30 22:37:18 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2017-03-06 03:13:09 +01:00
|
|
|
module.exports = {
|
2019-08-12 08:52:18 +02:00
|
|
|
kOutHeaders: Symbol('kOutHeaders'),
|
2019-08-11 11:09:40 +02:00
|
|
|
kNeedDrain: Symbol('kNeedDrain'),
|
2018-08-23 16:46:07 +02:00
|
|
|
nowDate,
|
2019-06-30 22:37:18 +02:00
|
|
|
utcDate,
|
|
|
|
emitStatistics
|
2017-03-06 03:13:09 +01:00
|
|
|
};
|