@@ -27,6 +27,7 @@ const {
27
27
ObjectDefineProperties,
28
28
ObjectDefineProperty,
29
29
ReflectApply,
30
+ Symbol,
30
31
} = primordials ;
31
32
32
33
const cares = internalBinding ( 'cares_wrap' ) ;
@@ -63,6 +64,15 @@ const {
63
64
QueryReqWrap,
64
65
} = cares ;
65
66
67
+ const kPerfHooksDnsLookupContext = Symbol ( 'kPerfHooksDnsLookupContext' ) ;
68
+ const kPerfHooksDnsLookupServiceContext = Symbol ( 'kPerfHooksDnsLookupServiceContext' ) ;
69
+ const kPerfHooksDnsLookupResolveContext = Symbol ( 'kPerfHooksDnsLookupResolveContext' ) ;
70
+
71
+ const {
72
+ startPerf,
73
+ stopPerf,
74
+ } = require ( 'internal/perf/observe' ) ;
75
+
66
76
const dnsException = errors . dnsException ;
67
77
68
78
let promises = null ; // Lazy loaded
@@ -72,6 +82,7 @@ function onlookup(err, addresses) {
72
82
return this . callback ( dnsException ( err , 'getaddrinfo' , this . hostname ) ) ;
73
83
}
74
84
this . callback ( null , addresses [ 0 ] , this . family || isIP ( addresses [ 0 ] ) ) ;
85
+ stopPerf ( this , kPerfHooksDnsLookupContext ) ;
75
86
}
76
87
77
88
@@ -90,6 +101,7 @@ function onlookupall(err, addresses) {
90
101
}
91
102
92
103
this . callback ( null , addresses ) ;
104
+ stopPerf ( this , kPerfHooksDnsLookupContext ) ;
93
105
}
94
106
95
107
@@ -176,6 +188,13 @@ function lookup(hostname, options, callback) {
176
188
process . nextTick ( callback , dnsException ( err , 'getaddrinfo' , hostname ) ) ;
177
189
return { } ;
178
190
}
191
+ const detail = {
192
+ hostname,
193
+ family,
194
+ hints,
195
+ verbatim,
196
+ } ;
197
+ startPerf ( req , kPerfHooksDnsLookupContext , { type : 'dns' , name : 'lookup' , detail } ) ;
179
198
return req ;
180
199
}
181
200
@@ -188,6 +207,7 @@ function onlookupservice(err, hostname, service) {
188
207
return this . callback ( dnsException ( err , 'getnameinfo' , this . hostname ) ) ;
189
208
190
209
this . callback ( null , hostname , service ) ;
210
+ stopPerf ( this , kPerfHooksDnsLookupServiceContext ) ;
191
211
}
192
212
193
213
@@ -212,6 +232,14 @@ function lookupService(address, port, callback) {
212
232
213
233
const err = cares . getnameinfo ( req , address , port ) ;
214
234
if ( err ) throw dnsException ( err , 'getnameinfo' , address ) ;
235
+ startPerf ( req , kPerfHooksDnsLookupServiceContext , {
236
+ type : 'dns' ,
237
+ name : 'lookupService' ,
238
+ detail : {
239
+ host : address ,
240
+ port
241
+ }
242
+ } ) ;
215
243
return req ;
216
244
}
217
245
@@ -226,8 +254,10 @@ function onresolve(err, result, ttls) {
226
254
227
255
if ( err )
228
256
this . callback ( dnsException ( err , this . bindingName , this . hostname ) ) ;
229
- else
257
+ else {
230
258
this . callback ( null , result ) ;
259
+ stopPerf ( this , kPerfHooksDnsLookupResolveContext ) ;
260
+ }
231
261
}
232
262
233
263
function resolver ( bindingName ) {
@@ -249,6 +279,14 @@ function resolver(bindingName) {
249
279
req . ttl = ! ! ( options && options . ttl ) ;
250
280
const err = this . _handle [ bindingName ] ( req , toASCII ( name ) ) ;
251
281
if ( err ) throw dnsException ( err , bindingName , name ) ;
282
+ startPerf ( req , kPerfHooksDnsLookupResolveContext , {
283
+ type : 'dns' ,
284
+ name : bindingName ,
285
+ detail : {
286
+ host : name ,
287
+ ttl : req . ttl
288
+ }
289
+ } ) ;
252
290
return req ;
253
291
}
254
292
ObjectDefineProperty ( query , 'name' , { value : bindingName } ) ;
0 commit comments