@@ -27,6 +27,7 @@ const {
2727 ObjectDefineProperties,
2828 ObjectDefineProperty,
2929 ReflectApply,
30+ Symbol,
3031} = primordials ;
3132
3233const cares = internalBinding ( 'cares_wrap' ) ;
@@ -62,6 +63,15 @@ const {
6263 QueryReqWrap,
6364} = cares ;
6465
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+
6575const dnsException = errors . dnsException ;
6676
6777let promises = null ; // Lazy loaded
@@ -71,6 +81,7 @@ function onlookup(err, addresses) {
7181 return this . callback ( dnsException ( err , 'getaddrinfo' , this . hostname ) ) ;
7282 }
7383 this . callback ( null , addresses [ 0 ] , this . family || isIP ( addresses [ 0 ] ) ) ;
84+ stopPerf ( this , kPerfHooksDnsLookupContext ) ;
7485}
7586
7687
@@ -89,6 +100,7 @@ function onlookupall(err, addresses) {
89100 }
90101
91102 this . callback ( null , addresses ) ;
103+ stopPerf ( this , kPerfHooksDnsLookupContext ) ;
92104}
93105
94106
@@ -161,6 +173,13 @@ function lookup(hostname, options, callback) {
161173 process . nextTick ( callback , dnsException ( err , 'getaddrinfo' , hostname ) ) ;
162174 return { } ;
163175 }
176+ const detail = {
177+ hostname,
178+ family,
179+ hints,
180+ verbatim,
181+ } ;
182+ startPerf ( req , kPerfHooksDnsLookupContext , { type : 'dns' , name : 'lookup' , detail } ) ;
164183 return req ;
165184}
166185
@@ -173,6 +192,7 @@ function onlookupservice(err, hostname, service) {
173192 return this . callback ( dnsException ( err , 'getnameinfo' , this . hostname ) ) ;
174193
175194 this . callback ( null , hostname , service ) ;
195+ stopPerf ( this , kPerfHooksDnsLookupServiceContext ) ;
176196}
177197
178198
@@ -197,6 +217,14 @@ function lookupService(address, port, callback) {
197217
198218 const err = cares . getnameinfo ( req , address , port ) ;
199219 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+ } ) ;
200228 return req ;
201229}
202230
@@ -211,8 +239,10 @@ function onresolve(err, result, ttls) {
211239
212240 if ( err )
213241 this . callback ( dnsException ( err , this . bindingName , this . hostname ) ) ;
214- else
242+ else {
215243 this . callback ( null , result ) ;
244+ stopPerf ( this , kPerfHooksDnsLookupResolveContext ) ;
245+ }
216246}
217247
218248function resolver ( bindingName ) {
@@ -234,6 +264,14 @@ function resolver(bindingName) {
234264 req . ttl = ! ! ( options && options . ttl ) ;
235265 const err = this . _handle [ bindingName ] ( req , toASCII ( name ) ) ;
236266 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+ } ) ;
237275 return req ;
238276 }
239277 ObjectDefineProperty ( query , 'name' , { value : bindingName } ) ;
0 commit comments