| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d558b3c commit 9803b82
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,6 +70,7 @@ const kPerfHooksDnsLookupServiceContext = Symbol('kPerfHooksDnsLookupServiceCont | |||
| 70 | 70 | const kPerfHooksDnsLookupResolveContext = Symbol('kPerfHooksDnsLookupResolveContext'); | |
| 71 | 71 | ||
| 72 | 72 | const { | |
| 73 | + hasObserver, | ||
| 73 | 74 | startPerf, | |
| 74 | 75 | stopPerf, | |
| 75 | 76 | } = require('internal/perf/observe'); | |
@@ -83,7 +84,9 @@ function onlookup(err, addresses) { | |||
| 83 | 84 | return this.callback(dnsException(err, 'getaddrinfo', this.hostname)); | |
| 84 | 85 | } | |
| 85 | 86 | this.callback(null, addresses[0], this.family || isIP(addresses[0])); | |
| 86 | - stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 87 | + if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) { | ||
| 88 | + stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 89 | + } | ||
| 87 | 90 | } | |
| 88 | 91 | ||
| 89 | 92 | ||
@@ -102,7 +105,9 @@ function onlookupall(err, addresses) { | |||
| 102 | 105 | } | |
| 103 | 106 | ||
| 104 | 107 | this.callback(null, addresses); | |
| 105 | - stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 108 | + if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) { | ||
| 109 | + stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 110 | + } | ||
| 106 | 111 | } | |
| 107 | 112 | ||
| 108 | 113 | ||
@@ -187,13 +192,15 @@ function lookup(hostname, options, callback) { | |||
| 187 | 192 | process.nextTick(callback, dnsException(err, 'getaddrinfo', hostname)); | |
| 188 | 193 | return {}; | |
| 189 | 194 | } | |
| 190 | - const detail = { | ||
| 191 | - hostname, | ||
| 192 | - family, | ||
| 193 | - hints, | ||
| 194 | - verbatim, | ||
| 195 | - }; | ||
| 196 | - startPerf(req, kPerfHooksDnsLookupContext, { type: 'dns', name: 'lookup', detail }); | ||
| 195 | + if (hasObserver('dns')) { | ||
| 196 | + const detail = { | ||
| 197 | + hostname, | ||
| 198 | + family, | ||
| 199 | + hints, | ||
| 200 | + verbatim, | ||
| 201 | + }; | ||
| 202 | + startPerf(req, kPerfHooksDnsLookupContext, { type: 'dns', name: 'lookup', detail }); | ||
| 203 | + } | ||
| 197 | 204 | return req; | |
| 198 | 205 | } | |
| 199 | 206 | ||
@@ -206,7 +213,9 @@ function onlookupservice(err, hostname, service) { | |||
| 206 | 213 | return this.callback(dnsException(err, 'getnameinfo', this.hostname)); | |
| 207 | 214 | ||
| 208 | 215 | this.callback(null, hostname, service); | |
| 209 | - stopPerf(this, kPerfHooksDnsLookupServiceContext); | ||
| 216 | + if (this[kPerfHooksDnsLookupServiceContext] && hasObserver('dns')) { | ||
| 217 | + stopPerf(this, kPerfHooksDnsLookupServiceContext); | ||
| 218 | + } | ||
| 210 | 219 | } | |
| 211 | 220 | ||
| 212 | 221 | ||
@@ -231,14 +240,16 @@ function lookupService(address, port, callback) { | |||
| 231 | 240 | ||
| 232 | 241 | const err = cares.getnameinfo(req, address, port); | |
| 233 | 242 | if (err) throw dnsException(err, 'getnameinfo', address); | |
| 234 | - startPerf(req, kPerfHooksDnsLookupServiceContext, { | ||
| 235 | - type: 'dns', | ||
| 236 | - name: 'lookupService', | ||
| 237 | - detail: { | ||
| 238 | - host: address, | ||
| 239 | - port | ||
| 240 | - } | ||
| 241 | - }); | ||
| 243 | + if (hasObserver('dns')) { | ||
| 244 | + startPerf(req, kPerfHooksDnsLookupServiceContext, { | ||
| 245 | + type: 'dns', | ||
| 246 | + name: 'lookupService', | ||
| 247 | + detail: { | ||
| 248 | + host: address, | ||
| 249 | + port, | ||
| 250 | + }, | ||
| 251 | + }); | ||
| 252 | + } | ||
| 242 | 253 | return req; | |
| 243 | 254 | } | |
| 244 | 255 | ||
@@ -255,7 +266,9 @@ function onresolve(err, result, ttls) { | |||
| 255 | 266 | this.callback(dnsException(err, this.bindingName, this.hostname)); | |
| 256 | 267 | else { | |
| 257 | 268 | this.callback(null, result); | |
| 258 | - stopPerf(this, kPerfHooksDnsLookupResolveContext); | ||
| 269 | + if (this[kPerfHooksDnsLookupResolveContext] && hasObserver('dns')) { | ||
| 270 | + stopPerf(this, kPerfHooksDnsLookupResolveContext); | ||
| 271 | + } | ||
| 259 | 272 | } | |
| 260 | 273 | } | |
| 261 | 274 | ||
@@ -278,14 +291,16 @@ function resolver(bindingName) { | |||
| 278 | 291 | req.ttl = !!(options && options.ttl); | |
| 279 | 292 | const err = this._handle[bindingName](req, toASCII(name)); | |
| 280 | 293 | if (err) throw dnsException(err, bindingName, name); | |
| 281 | - startPerf(req, kPerfHooksDnsLookupResolveContext, { | ||
| 282 | - type: 'dns', | ||
| 283 | - name: bindingName, | ||
| 284 | - detail: { | ||
| 285 | - host: name, | ||
| 286 | - ttl: req.ttl | ||
| 287 | - } | ||
| 288 | - }); | ||
| 294 | + if (hasObserver('dns')) { | ||
| 295 | + startPerf(req, kPerfHooksDnsLookupResolveContext, { | ||
| 296 | + type: 'dns', | ||
| 297 | + name: bindingName, | ||
| 298 | + detail: { | ||
| 299 | + host: name, | ||
| 300 | + ttl: req.ttl, | ||
| 301 | + }, | ||
| 302 | + }); | ||
| 303 | + } | ||
| 289 | 304 | return req; | |
| 290 | 305 | } | |
| 291 | 306 | ObjectDefineProperty(query, 'name', { __proto__: null, value: bindingName }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,7 @@ const kPerfHooksDnsLookupServiceContext = Symbol('kPerfHooksDnsLookupServiceCont | |||
| 46 | 46 | const kPerfHooksDnsLookupResolveContext = Symbol('kPerfHooksDnsLookupResolveContext'); | |
| 47 | 47 | ||
| 48 | 48 | const { | |
| 49 | + hasObserver, | ||
| 49 | 50 | startPerf, | |
| 50 | 51 | stopPerf, | |
| 51 | 52 | } = require('internal/perf/observe'); | |
@@ -58,7 +59,9 @@ function onlookup(err, addresses) { | |||
| 58 | 59 | ||
| 59 | 60 | const family = this.family || isIP(addresses[0]); | |
| 60 | 61 | this.resolve({ address: addresses[0], family }); | |
| 61 | - stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 62 | + if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) { | ||
| 63 | + stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 64 | + } | ||
| 62 | 65 | } | |
| 63 | 66 | ||
| 64 | 67 | function onlookupall(err, addresses) { | |
@@ -79,7 +82,9 @@ function onlookupall(err, addresses) { | |||
| 79 | 82 | } | |
| 80 | 83 | ||
| 81 | 84 | this.resolve(addresses); | |
| 82 | - stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 85 | + if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) { | ||
| 86 | + stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 87 | + } | ||
| 83 | 88 | } | |
| 84 | 89 | ||
| 85 | 90 | function createLookupPromise(family, hostname, all, hints, verbatim) { | |
@@ -110,7 +115,7 @@ function createLookupPromise(family, hostname, all, hints, verbatim) { | |||
| 110 | 115 | ||
| 111 | 116 | if (err) { | |
| 112 | 117 | reject(dnsException(err, 'getaddrinfo', hostname)); | |
| 113 | - } else { | ||
| 118 | + } else if (hasObserver('dns')) { | ||
| 114 | 119 | const detail = { | |
| 115 | 120 | hostname, | |
| 116 | 121 | family, | |
@@ -170,7 +175,9 @@ function onlookupservice(err, hostname, service) { | |||
| 170 | 175 | } | |
| 171 | 176 | ||
| 172 | 177 | this.resolve({ hostname, service }); | |
| 173 | - stopPerf(this, kPerfHooksDnsLookupServiceContext); | ||
| 178 | + if (this[kPerfHooksDnsLookupServiceContext] && hasObserver('dns')) { | ||
| 179 | + stopPerf(this, kPerfHooksDnsLookupServiceContext); | ||
| 180 | + } | ||
| 174 | 181 | } | |
| 175 | 182 | ||
| 176 | 183 | function createLookupServicePromise(hostname, port) { | |
@@ -187,7 +194,7 @@ function createLookupServicePromise(hostname, port) { | |||
| 187 | 194 | ||
| 188 | 195 | if (err) | |
| 189 | 196 | reject(dnsException(err, 'getnameinfo', hostname)); | |
| 190 | - else | ||
| 197 | + else if (hasObserver('dns')) { | ||
| 191 | 198 | startPerf(req, kPerfHooksDnsLookupServiceContext, { | |
| 192 | 199 | type: 'dns', | |
| 193 | 200 | name: 'lookupService', | |
@@ -196,6 +203,7 @@ function createLookupServicePromise(hostname, port) { | |||
| 196 | 203 | port | |
| 197 | 204 | } | |
| 198 | 205 | }); | |
| 206 | + } | ||
| 199 | 207 | }); | |
| 200 | 208 | } | |
| 201 | 209 | ||
@@ -223,7 +231,9 @@ function onresolve(err, result, ttls) { | |||
| 223 | 231 | result, (address, index) => ({ address, ttl: ttls[index] })); | |
| 224 | 232 | ||
| 225 | 233 | this.resolve(result); | |
| 226 | - stopPerf(this, kPerfHooksDnsLookupResolveContext); | ||
| 234 | + if (this[kPerfHooksDnsLookupResolveContext] && hasObserver('dns')) { | ||
| 235 | + stopPerf(this, kPerfHooksDnsLookupResolveContext); | ||
| 236 | + } | ||
| 227 | 237 | } | |
| 228 | 238 | ||
| 229 | 239 | function createResolverPromise(resolver, bindingName, hostname, ttl) { | |
@@ -241,7 +251,7 @@ function createResolverPromise(resolver, bindingName, hostname, ttl) { | |||
| 241 | 251 | ||
| 242 | 252 | if (err) | |
| 243 | 253 | reject(dnsException(err, bindingName, hostname)); | |
| 244 | - else { | ||
| 254 | + else if (hasObserver('dns')) { | ||
| 245 | 255 | startPerf(req, kPerfHooksDnsLookupResolveContext, { | |
| 246 | 256 | type: 'dns', | |
| 247 | 257 | name: bindingName, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -460,27 +460,26 @@ function hasObserver(type) { | |||
| 460 | 460 | ||
| 461 | 461 | ||
| 462 | 462 | function startPerf(target, key, context = {}) { | |
| 463 | - if (hasObserver(context.type)) { | ||
| 464 | - target[key] = { | ||
| 465 | - ...context, | ||
| 466 | - startTime: now(), | ||
| 467 | - }; | ||
| 468 | - } | ||
| 463 | + target[key] = { | ||
| 464 | + ...context, | ||
| 465 | + startTime: now(), | ||
| 466 | + }; | ||
| 469 | 467 | } | |
| 470 | 468 | ||
| 471 | 469 | function stopPerf(target, key, context = {}) { | |
| 472 | 470 | const ctx = target[key]; | |
| 473 | - if (ctx && hasObserver(ctx.type)) { | ||
| 474 | - const startTime = ctx.startTime; | ||
| 475 | - const entry = new InternalPerformanceEntry( | ||
| 476 | - ctx.name, | ||
| 477 | - ctx.type, | ||
| 478 | - startTime, | ||
| 479 | - now() - startTime, | ||
| 480 | - { ...ctx.detail, ...context.detail }, | ||
| 481 | - ); | ||
| 482 | - enqueue(entry); | ||
| 471 | + if (!ctx) { | ||
| 472 | + return; | ||
| 483 | 473 | } | |
| 474 | + const startTime = ctx.startTime; | ||
| 475 | + const entry = new InternalPerformanceEntry( | ||
| 476 | + ctx.name, | ||
| 477 | + ctx.type, | ||
| 478 | + startTime, | ||
| 479 | + now() - startTime, | ||
| 480 | + { ...ctx.detail, ...context.detail }, | ||
| 481 | + ); | ||
| 482 | + enqueue(entry); | ||
| 484 | 483 | } | |
| 485 | 484 | ||
| 486 | 485 | module.exports = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -133,6 +133,7 @@ const noop = () => {}; | |||
| 133 | 133 | ||
| 134 | 134 | const kPerfHooksNetConnectContext = Symbol('kPerfHooksNetConnectContext'); | |
| 135 | 135 | const { | |
| 136 | + hasObserver, | ||
| 136 | 137 | startPerf, | |
| 137 | 138 | stopPerf, | |
| 138 | 139 | } = require('internal/perf/observe'); | |
@@ -999,7 +1000,7 @@ function internalConnect( | |||
| 999 | 1000 | ||
| 1000 | 1001 | const ex = exceptionWithHostPort(err, 'connect', address, port, details); | |
| 1001 | 1002 | self.destroy(ex); | |
| 1002 | - } else if (addressType === 6 || addressType === 4) { | ||
| 1003 | + } else if ((addressType === 6 || addressType === 4) && hasObserver('net')) { | ||
| 1003 | 1004 | startPerf(self, kPerfHooksNetConnectContext, { type: 'net', name: 'connect', detail: { host: address, port } }); | |
| 1004 | 1005 | } | |
| 1005 | 1006 | } | |
@@ -1226,7 +1227,9 @@ function afterConnect(status, handle, req, readable, writable) { | |||
| 1226 | 1227 | // this doesn't actually consume any bytes, because len=0. | |
| 1227 | 1228 | if (readable && !self.isPaused()) | |
| 1228 | 1229 | self.read(0); | |
| 1229 | - stopPerf(self, kPerfHooksNetConnectContext); | ||
| 1230 | + if (self[kPerfHooksNetConnectContext] && hasObserver('net')) { | ||
| 1231 | + stopPerf(self, kPerfHooksNetConnectContext); | ||
| 1232 | + } | ||
| 1230 | 1233 | } else { | |
| 1231 | 1234 | self.connecting = false; | |
| 1232 | 1235 | let details; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments