@@ -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' ) ;
@@ -62,6 +63,15 @@ const {
62
63
QueryReqWrap,
63
64
} = cares ;
64
65
66
+ const kPerfHooksDnsLookupContext = Symbol ( 'kPerfHooksDnsLookupContext' ) ;
67
+ const kPerfHooksDnsLookupServiceContext = Symbol ( 'kPerfHooksDnsLookupServiceContext' ) ;
68
+ const kPerfHooksDnsLookupResolveContext = Symbol ( 'kPerfHooksDnsLookupResolveContext' ) ;
69
+
70
+ const {
71
+ startPerf,
72
+ stopPerf,
73
+ } = require ( 'internal/perf/observe' ) ;
74
+
65
75
const dnsException = errors . dnsException ;
66
76
67
77
let promises = null ; // Lazy loaded
@@ -71,6 +81,7 @@ function onlookup(err, addresses) {
71
81
return this . callback ( dnsException ( err , 'getaddrinfo' , this . hostname ) ) ;
72
82
}
73
83
this . callback ( null , addresses [ 0 ] , this . family || isIP ( addresses [ 0 ] ) ) ;
84
+ stopPerf ( this , kPerfHooksDnsLookupContext ) ;
74
85
}
75
86
76
87
@@ -89,6 +100,7 @@ function onlookupall(err, addresses) {
89
100
}
90
101
91
102
this . callback ( null , addresses ) ;
103
+ stopPerf ( this , kPerfHooksDnsLookupContext ) ;
92
104
}
93
105
94
106
@@ -161,6 +173,13 @@ function lookup(hostname, options, callback) {
161
173
process . nextTick ( callback , dnsException ( err , 'getaddrinfo' , hostname ) ) ;
162
174
return { } ;
163
175
}
176
+ const detail = {
177
+ hostname,
178
+ family,
179
+ hints,
180
+ verbatim,
181
+ } ;
182
+ startPerf ( req , kPerfHooksDnsLookupContext , { type : 'dns' , name : 'lookup' , detail } ) ;
164
183
return req ;
165
184
}
166
185
@@ -173,6 +192,7 @@ function onlookupservice(err, hostname, service) {
173
192
return this . callback ( dnsException ( err , 'getnameinfo' , this . hostname ) ) ;
174
193
175
194
this . callback ( null , hostname , service ) ;
195
+ stopPerf ( this , kPerfHooksDnsLookupServiceContext ) ;
176
196
}
177
197
178
198
@@ -197,6 +217,14 @@ function lookupService(address, port, callback) {
197
217
198
218
const err = cares . getnameinfo ( req , address , port ) ;
199
219
if ( err ) throw dnsException ( err , 'getnameinfo' , address ) ;
220
+ startPerf ( req , kPerfHooksDnsLookupServiceContext , {
221
+ type : 'dns' ,
222
+ name : 'lookupService' ,
223
+ detail : {
224
+ host : address ,
225
+ port
226
+ }
227
+ } ) ;
200
228
return req ;
201
229
}
202
230
@@ -211,8 +239,10 @@ function onresolve(err, result, ttls) {
211
239
212
240
if ( err )
213
241
this . callback ( dnsException ( err , this . bindingName , this . hostname ) ) ;
214
- else
242
+ else {
215
243
this . callback ( null , result ) ;
244
+ stopPerf ( this , kPerfHooksDnsLookupResolveContext ) ;
245
+ }
216
246
}
217
247
218
248
function resolver ( bindingName ) {
@@ -234,6 +264,14 @@ function resolver(bindingName) {
234
264
req . ttl = ! ! ( options && options . ttl ) ;
235
265
const err = this . _handle [ bindingName ] ( req , toASCII ( name ) ) ;
236
266
if ( err ) throw dnsException ( err , bindingName , name ) ;
267
+ startPerf ( req , kPerfHooksDnsLookupResolveContext , {
268
+ type : 'dns' ,
269
+ name : bindingName ,
270
+ detail : {
271
+ host : name ,
272
+ ttl : req . ttl
273
+ }
274
+ } ) ;
237
275
return req ;
238
276
}
239
277
ObjectDefineProperty ( query , 'name' , { value : bindingName } ) ;
0 commit comments