@@ -38,7 +38,12 @@ const {
38
38
_checkInvalidHeaderChar : checkInvalidHeaderChar
39
39
} = require ( '_http_common' ) ;
40
40
const { OutgoingMessage } = require ( '_http_outgoing' ) ;
41
- const { outHeadersKey, ondrain, nowDate } = require ( 'internal/http' ) ;
41
+ const {
42
+ outHeadersKey,
43
+ ondrain,
44
+ nowDate,
45
+ emitStatistics
46
+ } = require ( 'internal/http' ) ;
42
47
const {
43
48
defaultTriggerAsyncIdScope,
44
49
getOrSetAsyncId
@@ -55,8 +60,11 @@ const {
55
60
DTRACE_HTTP_SERVER_REQUEST ,
56
61
DTRACE_HTTP_SERVER_RESPONSE
57
62
} = require ( 'internal/dtrace' ) ;
63
+ const { observerCounts, constants } = internalBinding ( 'performance' ) ;
64
+ const { NODE_PERFORMANCE_ENTRY_TYPE_HTTP } = constants ;
58
65
59
66
const kServerResponse = Symbol ( 'ServerResponse' ) ;
67
+ const kServerResponseStatistics = Symbol ( 'ServerResponseStatistics' ) ;
60
68
61
69
const STATUS_CODES = {
62
70
100 : 'Continue' ,
@@ -146,12 +154,22 @@ function ServerResponse(req) {
146
154
this . useChunkedEncodingByDefault = chunkExpression . test ( req . headers . te ) ;
147
155
this . shouldKeepAlive = false ;
148
156
}
157
+
158
+ const httpObserverCount = observerCounts [ NODE_PERFORMANCE_ENTRY_TYPE_HTTP ] ;
159
+ if ( httpObserverCount > 0 ) {
160
+ this [ kServerResponseStatistics ] = {
161
+ startTime : process . hrtime ( )
162
+ } ;
163
+ }
149
164
}
150
165
Object . setPrototypeOf ( ServerResponse . prototype , OutgoingMessage . prototype ) ;
151
166
Object . setPrototypeOf ( ServerResponse , OutgoingMessage ) ;
152
167
153
168
ServerResponse . prototype . _finish = function _finish ( ) {
154
169
DTRACE_HTTP_SERVER_RESPONSE ( this . connection ) ;
170
+ if ( this [ kServerResponseStatistics ] !== undefined ) {
171
+ emitStatistics ( this [ kServerResponseStatistics ] ) ;
172
+ }
155
173
OutgoingMessage . prototype . _finish . call ( this ) ;
156
174
} ;
157
175
0 commit comments