diff options
Diffstat (limited to 'lib/_http_server.js')
-rw-r--r-- | lib/_http_server.js | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/_http_server.js b/lib/_http_server.js index 941d571a67..6a262eedc2 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -39,7 +39,12 @@ const { prepareError, } = require('_http_common'); const { OutgoingMessage } = require('_http_outgoing'); -const { outHeadersKey, ondrain, nowDate } = require('internal/http'); +const { + outHeadersKey, + ondrain, + nowDate, + emitStatistics +} = require('internal/http'); const { defaultTriggerAsyncIdScope, getOrSetAsyncId @@ -56,8 +61,11 @@ const { DTRACE_HTTP_SERVER_REQUEST, DTRACE_HTTP_SERVER_RESPONSE } = require('internal/dtrace'); +const { observerCounts, constants } = internalBinding('performance'); +const { NODE_PERFORMANCE_ENTRY_TYPE_HTTP } = constants; const kServerResponse = Symbol('ServerResponse'); +const kServerResponseStatistics = Symbol('ServerResponseStatistics'); const STATUS_CODES = { 100: 'Continue', @@ -147,12 +155,22 @@ function ServerResponse(req) { this.useChunkedEncodingByDefault = chunkExpression.test(req.headers.te); this.shouldKeepAlive = false; } + + const httpObserverCount = observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_HTTP]; + if (httpObserverCount > 0) { + this[kServerResponseStatistics] = { + startTime: process.hrtime() + }; + } } Object.setPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype); Object.setPrototypeOf(ServerResponse, OutgoingMessage); ServerResponse.prototype._finish = function _finish() { DTRACE_HTTP_SERVER_RESPONSE(this.connection); + if (this[kServerResponseStatistics] !== undefined) { + emitStatistics(this[kServerResponseStatistics]); + } OutgoingMessage.prototype._finish.call(this); }; |