@@ -39,7 +39,12 @@ const {
3939 prepareError,
4040} = require ( '_http_common' ) ;
4141const { OutgoingMessage } = require ( '_http_outgoing' ) ;
42- const { outHeadersKey, ondrain, nowDate } = require ( 'internal/http' ) ;
42+ const {
43+ outHeadersKey,
44+ ondrain,
45+ nowDate,
46+ emitStatistics
47+ } = require ( 'internal/http' ) ;
4348const {
4449 defaultTriggerAsyncIdScope,
4550 getOrSetAsyncId
@@ -57,8 +62,11 @@ const {
5762 DTRACE_HTTP_SERVER_RESPONSE
5863} = require ( 'internal/dtrace' ) ;
5964const { getOptionValue } = require ( 'internal/options' ) ;
65+ const { observerCounts, constants } = internalBinding ( 'performance' ) ;
66+ const { NODE_PERFORMANCE_ENTRY_TYPE_HTTP } = constants ;
6067
6168const kServerResponse = Symbol ( 'ServerResponse' ) ;
69+ const kServerResponseStatistics = Symbol ( 'ServerResponseStatistics' ) ;
6270const kDefaultHttpServerTimeout =
6371 getOptionValue ( '--http-server-default-timeout' ) ;
6472
@@ -150,12 +158,22 @@ function ServerResponse(req) {
150158 this . useChunkedEncodingByDefault = chunkExpression . test ( req . headers . te ) ;
151159 this . shouldKeepAlive = false ;
152160 }
161+
162+ const httpObserverCount = observerCounts [ NODE_PERFORMANCE_ENTRY_TYPE_HTTP ] ;
163+ if ( httpObserverCount > 0 ) {
164+ this [ kServerResponseStatistics ] = {
165+ startTime : process . hrtime ( )
166+ } ;
167+ }
153168}
154169Object . setPrototypeOf ( ServerResponse . prototype , OutgoingMessage . prototype ) ;
155170Object . setPrototypeOf ( ServerResponse , OutgoingMessage ) ;
156171
157172ServerResponse . prototype . _finish = function _finish ( ) {
158173 DTRACE_HTTP_SERVER_RESPONSE ( this . connection ) ;
174+ if ( this [ kServerResponseStatistics ] !== undefined ) {
175+ emitStatistics ( this [ kServerResponseStatistics ] ) ;
176+ }
159177 OutgoingMessage . prototype . _finish . call ( this ) ;
160178} ;
161179
0 commit comments