@@ -27,6 +27,7 @@ const {
2727 ObjectDefineProperties,
2828 ObjectDefineProperty,
2929 ReflectApply,
30+ Symbol,
3031} = primordials ;
3132
3233const cares = internalBinding ( 'cares_wrap' ) ;
@@ -63,6 +64,15 @@ const {
6364 QueryReqWrap,
6465} = cares ;
6566
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+
6676const dnsException = errors . dnsException ;
6777
6878let promises = null ; // Lazy loaded
@@ -72,6 +82,7 @@ function onlookup(err, addresses) {
7282 return this . callback ( dnsException ( err , 'getaddrinfo' , this . hostname ) ) ;
7383 }
7484 this . callback ( null , addresses [ 0 ] , this . family || isIP ( addresses [ 0 ] ) ) ;
85+ stopPerf ( this , kPerfHooksDnsLookupContext ) ;
7586}
7687
7788
@@ -90,6 +101,7 @@ function onlookupall(err, addresses) {
90101 }
91102
92103 this . callback ( null , addresses ) ;
104+ stopPerf ( this , kPerfHooksDnsLookupContext ) ;
93105}
94106
95107
@@ -176,6 +188,13 @@ function lookup(hostname, options, callback) {
176188 process . nextTick ( callback , dnsException ( err , 'getaddrinfo' , hostname ) ) ;
177189 return { } ;
178190 }
191+ const detail = {
192+ hostname,
193+ family,
194+ hints,
195+ verbatim,
196+ } ;
197+ startPerf ( req , kPerfHooksDnsLookupContext , { type : 'dns' , name : 'lookup' , detail } ) ;
179198 return req ;
180199}
181200
@@ -188,6 +207,7 @@ function onlookupservice(err, hostname, service) {
188207 return this . callback ( dnsException ( err , 'getnameinfo' , this . hostname ) ) ;
189208
190209 this . callback ( null , hostname , service ) ;
210+ stopPerf ( this , kPerfHooksDnsLookupServiceContext ) ;
191211}
192212
193213
@@ -212,6 +232,14 @@ function lookupService(address, port, callback) {
212232
213233 const err = cares . getnameinfo ( req , address , port ) ;
214234 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+ } ) ;
215243 return req ;
216244}
217245
@@ -226,8 +254,10 @@ function onresolve(err, result, ttls) {
226254
227255 if ( err )
228256 this . callback ( dnsException ( err , this . bindingName , this . hostname ) ) ;
229- else
257+ else {
230258 this . callback ( null , result ) ;
259+ stopPerf ( this , kPerfHooksDnsLookupResolveContext ) ;
260+ }
231261}
232262
233263function resolver ( bindingName ) {
@@ -249,6 +279,14 @@ function resolver(bindingName) {
249279 req . ttl = ! ! ( options && options . ttl ) ;
250280 const err = this . _handle [ bindingName ] ( req , toASCII ( name ) ) ;
251281 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+ } ) ;
252290 return req ;
253291 }
254292 ObjectDefineProperty ( query , 'name' , { value : bindingName } ) ;
0 commit comments