| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 763a63c commit 9dad4b0
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -425,6 +425,24 @@ Emitted when server receives a request. | |||
| 425 | 425 | ||
| 426 | 426 | Emitted when server sends a response. | |
| 427 | 427 | ||
| 428 | + `net.client.socket` | ||
| 429 | + | ||
| 430 | + * `socket` {net.Socket} | ||
| 431 | + | ||
| 432 | + Emitted when a new TCP or pipe client socket is created. | ||
| 433 | + | ||
| 434 | + `net.server.socket` | ||
| 435 | + | ||
| 436 | + * `socket` {net.Socket} | ||
| 437 | + | ||
| 438 | + Emitted when a new TCP or pipe connection is received. | ||
| 439 | + | ||
| 440 | + `udp.socket` | ||
| 441 | + | ||
| 442 | + * `socket` {dgram.Socket} | ||
| 443 | + | ||
| 444 | + Emitted when a new UDP socket is created. | ||
| 445 | + | ||
| 428 | 446 | [`'uncaughtException'`]: process.md#event-uncaughtexception | |
| 429 | 447 | [`channel.subscribe(onMessage)`]: #channelsubscribeonmessage | |
| 430 | 448 | [`diagnostics_channel.channel(name)`]: #diagnostics_channelchannelname | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -602,13 +602,15 @@ When `performanceEntry.type` is equal to `'dns'`, the | |||
| 602 | 602 | additional information. | |
| 603 | 603 | ||
| 604 | 604 | If `performanceEntry.name` is equal to `lookup`, the `detail` | |
| 605 | - will contain the following properties: `hostname`, `family`, `hints`, `verbatim`. | ||
| 605 | + will contain the following properties: `hostname`, `family`, `hints`, `verbatim`, | ||
| 606 | + `addresses`. | ||
| 606 | 607 | ||
| 607 | 608 | If `performanceEntry.name` is equal to `lookupService`, the `detail` will | |
| 608 | - contain the following properties: `host`, `port`. | ||
| 609 | + contain the following properties: `host`, `port`, `hostname`, `service`. | ||
| 609 | 610 | ||
| 610 | 611 | If `performanceEntry.name` is equal to `queryxxx` or `getHostByAddr`, the `detail` will | |
| 611 | - contain the following properties: `host`, `ttl`. | ||
| 612 | + contain the following properties: `host`, `ttl`, `result`. The value of `result` is | ||
| 613 | + same as the result of `queryxxx` or `getHostByAddr`. | ||
| 612 | 614 | ||
| 613 | 615 | ## Class: `PerformanceNodeTiming` | |
| 614 | 616 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,9 @@ const { | |||
| 74 | 74 | SendWrap | |
| 75 | 75 | } = internalBinding('udp_wrap'); | |
| 76 | 76 | ||
| 77 | + const dc = require('diagnostics_channel'); | ||
| 78 | + const udpSocketChannel = dc.channel('udp.socket'); | ||
| 79 | + | ||
| 77 | 80 | const BIND_STATE_UNBOUND = 0; | |
| 78 | 81 | const BIND_STATE_BINDING = 1; | |
| 79 | 82 | const BIND_STATE_BOUND = 2; | |
@@ -145,6 +148,11 @@ function Socket(type, listener) { | |||
| 145 | 148 | this.once('close', () => signal.removeEventListener('abort', onAborted)); | |
| 146 | 149 | } | |
| 147 | 150 | } | |
| 151 | + if (udpSocketChannel.hasSubscribers) { | ||
| 152 | + udpSocketChannel.publish({ | ||
| 153 | + socket: this, | ||
| 154 | + }); | ||
| 155 | + } | ||
| 148 | 156 | } | |
| 149 | 157 | ObjectSetPrototypeOf(Socket.prototype, EventEmitter.prototype); | |
| 150 | 158 | ObjectSetPrototypeOf(Socket, EventEmitter); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -110,7 +110,7 @@ function onlookup(err, addresses) { | |||
| 110 | 110 | } | |
| 111 | 111 | this.callback(null, addresses[0], this.family || isIP(addresses[0])); | |
| 112 | 112 | if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) { | |
| 113 | - stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 113 | + stopPerf(this, kPerfHooksDnsLookupContext, { detail: { addresses } }); | ||
| 114 | 114 | } | |
| 115 | 115 | } | |
| 116 | 116 | ||
@@ -131,7 +131,7 @@ function onlookupall(err, addresses) { | |||
| 131 | 131 | ||
| 132 | 132 | this.callback(null, addresses); | |
| 133 | 133 | if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) { | |
| 134 | - stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 134 | + stopPerf(this, kPerfHooksDnsLookupContext, { detail: { addresses } }); | ||
| 135 | 135 | } | |
| 136 | 136 | } | |
| 137 | 137 | ||
@@ -227,7 +227,7 @@ function onlookupservice(err, hostname, service) { | |||
| 227 | 227 | ||
| 228 | 228 | this.callback(null, hostname, service); | |
| 229 | 229 | if (this[kPerfHooksDnsLookupServiceContext] && hasObserver('dns')) { | |
| 230 | - stopPerf(this, kPerfHooksDnsLookupServiceContext); | ||
| 230 | + stopPerf(this, kPerfHooksDnsLookupServiceContext, { detail: { hostname, service } }); | ||
| 231 | 231 | } | |
| 232 | 232 | } | |
| 233 | 233 | ||
@@ -280,7 +280,7 @@ function onresolve(err, result, ttls) { | |||
| 280 | 280 | else { | |
| 281 | 281 | this.callback(null, result); | |
| 282 | 282 | if (this[kPerfHooksDnsLookupResolveContext] && hasObserver('dns')) { | |
| 283 | - stopPerf(this, kPerfHooksDnsLookupResolveContext); | ||
| 283 | + stopPerf(this, kPerfHooksDnsLookupResolveContext, { detail: { result } }); | ||
| 284 | 284 | } | |
| 285 | 285 | } | |
| 286 | 286 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,7 +86,7 @@ function onlookup(err, addresses) { | |||
| 86 | 86 | const family = this.family || isIP(addresses[0]); | |
| 87 | 87 | this.resolve({ address: addresses[0], family }); | |
| 88 | 88 | if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) { | |
| 89 | - stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 89 | + stopPerf(this, kPerfHooksDnsLookupContext, { detail: { addresses } }); | ||
| 90 | 90 | } | |
| 91 | 91 | } | |
| 92 | 92 | ||
@@ -109,7 +109,7 @@ function onlookupall(err, addresses) { | |||
| 109 | 109 | ||
| 110 | 110 | this.resolve(addresses); | |
| 111 | 111 | if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) { | |
| 112 | - stopPerf(this, kPerfHooksDnsLookupContext); | ||
| 112 | + stopPerf(this, kPerfHooksDnsLookupContext, { detail: { addresses } }); | ||
| 113 | 113 | } | |
| 114 | 114 | } | |
| 115 | 115 | ||
@@ -191,7 +191,7 @@ function onlookupservice(err, hostname, service) { | |||
| 191 | 191 | ||
| 192 | 192 | this.resolve({ hostname, service }); | |
| 193 | 193 | if (this[kPerfHooksDnsLookupServiceContext] && hasObserver('dns')) { | |
| 194 | - stopPerf(this, kPerfHooksDnsLookupServiceContext); | ||
| 194 | + stopPerf(this, kPerfHooksDnsLookupServiceContext, { detail: { hostname, service } }); | ||
| 195 | 195 | } | |
| 196 | 196 | } | |
| 197 | 197 | ||
@@ -247,7 +247,7 @@ function onresolve(err, result, ttls) { | |||
| 247 | 247 | ||
| 248 | 248 | this.resolve(result); | |
| 249 | 249 | if (this[kPerfHooksDnsLookupResolveContext] && hasObserver('dns')) { | |
| 250 | - stopPerf(this, kPerfHooksDnsLookupResolveContext); | ||
| 250 | + stopPerf(this, kPerfHooksDnsLookupResolveContext, { detail: { result } }); | ||
| 251 | 251 | } | |
| 252 | 252 | } | |
| 253 | 253 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -133,6 +133,11 @@ const isWindows = process.platform === 'win32'; | |||
| 133 | 133 | const noop = () => {}; | |
| 134 | 134 | ||
| 135 | 135 | const kPerfHooksNetConnectContext = Symbol('kPerfHooksNetConnectContext'); | |
| 136 | + | ||
| 137 | + const dc = require('diagnostics_channel'); | ||
| 138 | + const netClientSocketChannel = dc.channel('net.client.socket'); | ||
| 139 | + const netServerSocketChannel = dc.channel('net.server.socket'); | ||
| 140 | + | ||
| 136 | 141 | const { | |
| 137 | 142 | hasObserver, | |
| 138 | 143 | startPerf, | |
@@ -204,7 +209,11 @@ function connect(...args) { | |||
| 204 | 209 | const options = normalized[0]; | |
| 205 | 210 | debug('createConnection', normalized); | |
| 206 | 211 | const socket = new Socket(options); | |
| 207 | - | ||
| 212 | + if (netClientSocketChannel.hasSubscribers) { | ||
| 213 | + netClientSocketChannel.publish({ | ||
| 214 | + socket, | ||
| 215 | + }); | ||
| 216 | + } | ||
| 208 | 217 | if (options.timeout) { | |
| 209 | 218 | socket.setTimeout(options.timeout); | |
| 210 | 219 | } | |
@@ -1714,6 +1723,11 @@ function onconnection(err, clientHandle) { | |||
| 1714 | 1723 | ||
| 1715 | 1724 | DTRACE_NET_SERVER_CONNECTION(socket); | |
| 1716 | 1725 | self.emit('connection', socket); | |
| 1726 | + if (netServerSocketChannel.hasSubscribers) { | ||
| 1727 | + netServerSocketChannel.publish({ | ||
| 1728 | + socket, | ||
| 1729 | + }); | ||
| 1730 | + } | ||
| 1717 | 1731 | } | |
| 1718 | 1732 | ||
| 1719 | 1733 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,6 +160,7 @@ const expectedModules = new Set([ | |||
| 160 | 160 | 'NativeModule v8', | |
| 161 | 161 | 'NativeModule internal/v8/startup_snapshot', | |
| 162 | 162 | 'NativeModule vm', | |
| 163 | + 'NativeModule diagnostics_channel', | ||
| 163 | 164 | ]); | |
| 164 | 165 | ||
| 165 | 166 | if (!common.isMainThread) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const net = require('net'); | ||
| 5 | + const dc = require('diagnostics_channel'); | ||
| 6 | + | ||
| 7 | + const netClientSocketChannel = dc.channel('net.client.socket'); | ||
| 8 | + const netServerSocketChannel = dc.channel('net.server.socket'); | ||
| 9 | + | ||
| 10 | + const isNetSocket = (socket) => socket instanceof net.Socket; | ||
| 11 | + | ||
| 12 | + netClientSocketChannel.subscribe(common.mustCall(({ socket }) => { | ||
| 13 | + assert.strictEqual(isNetSocket(socket), true); | ||
| 14 | + })); | ||
| 15 | + | ||
| 16 | + netServerSocketChannel.subscribe(common.mustCall(({ socket }) => { | ||
| 17 | + assert.strictEqual(isNetSocket(socket), true); | ||
| 18 | + })); | ||
| 19 | + | ||
| 20 | + const server = net.createServer(common.mustCall((socket) => { | ||
| 21 | + socket.destroy(); | ||
| 22 | + server.close(); | ||
| 23 | + })); | ||
| 24 | + | ||
| 25 | + server.listen(() => { | ||
| 26 | + const { port } = server.address(); | ||
| 27 | + net.connect(port); | ||
| 28 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const dgram = require('dgram'); | ||
| 5 | + const dc = require('diagnostics_channel'); | ||
| 6 | + | ||
| 7 | + const udpSocketChannel = dc.channel('udp.socket'); | ||
| 8 | + | ||
| 9 | + const isUDPSocket = (socket) => socket instanceof dgram.Socket; | ||
| 10 | + | ||
| 11 | + udpSocketChannel.subscribe(common.mustCall(({ socket }) => { | ||
| 12 | + assert.strictEqual(isUDPSocket(socket), true); | ||
| 13 | + })); | ||
| 14 | + const socket = dgram.createSocket('udp4'); | ||
| 15 | + socket.close(); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,21 +6,55 @@ const dns = require('dns'); | |||
| 6 | 6 | const { PerformanceObserver } = require('perf_hooks'); | |
| 7 | 7 | ||
| 8 | 8 | const entries = []; | |
| 9 | - const obs = new PerformanceObserver(common.mustCallAtLeast((items) => { | ||
| 9 | + const obs = new PerformanceObserver((items) => { | ||
| 10 | 10 | entries.push(...items.getEntries()); | |
| 11 | - })); | ||
| 11 | + }); | ||
| 12 | 12 | ||
| 13 | 13 | obs.observe({ type: 'dns' }); | |
| 14 | 14 | ||
| 15 | - dns.lookup('localhost', () => {}); | ||
| 15 | + let count = 0; | ||
| 16 | + | ||
| 17 | + function inc() { | ||
| 18 | + count++; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + // If DNS resolution fails, skip it | ||
| 22 | + // https://github.com/nodejs/node/issues/44003 | ||
| 23 | + dns.lookup('localhost', common.mustCall((err) => { !err && inc(); })); | ||
| 24 | + dns.lookupService('127.0.0.1', 80, common.mustCall((err) => { !err && inc(); })); | ||
| 25 | + dns.resolveAny('localhost', common.mustCall((err) => { !err && inc(); })); | ||
| 26 | + | ||
| 27 | + dns.promises.lookup('localhost').then(inc).catch(() => {}); | ||
| 28 | + dns.promises.lookupService('127.0.0.1', 80).then(inc).catch(() => {}); | ||
| 29 | + dns.promises.resolveAny('localhost').then(inc).catch(() => {}); | ||
| 16 | 30 | ||
| 17 | 31 | process.on('exit', () => { | |
| 18 | - assert.strictEqual(entries.length, 1); | ||
| 32 | + assert.strictEqual(entries.length, count); | ||
| 19 | 33 | entries.forEach((entry) => { | |
| 20 | 34 | assert.strictEqual(!!entry.name, true); | |
| 21 | 35 | assert.strictEqual(entry.entryType, 'dns'); | |
| 22 | 36 | assert.strictEqual(typeof entry.startTime, 'number'); | |
| 23 | 37 | assert.strictEqual(typeof entry.duration, 'number'); | |
| 24 | 38 | assert.strictEqual(typeof entry.detail, 'object'); | |
| 39 | + switch (entry.name) { | ||
| 40 | + case 'lookup': | ||
| 41 | + assert.strictEqual(typeof entry.detail.hostname, 'string'); | ||
| 42 | + assert.strictEqual(typeof entry.detail.family, 'number'); | ||
| 43 | + assert.strictEqual(typeof entry.detail.hints, 'number'); | ||
| 44 | + assert.strictEqual(typeof entry.detail.verbatim, 'boolean'); | ||
| 45 | + assert.strictEqual(Array.isArray(entry.detail.addresses), true); | ||
| 46 | + break; | ||
| 47 | + case 'lookupService': | ||
| 48 | + assert.strictEqual(typeof entry.detail.host, 'string'); | ||
| 49 | + assert.strictEqual(typeof entry.detail.port, 'number'); | ||
| 50 | + assert.strictEqual(typeof entry.detail.hostname, 'string'); | ||
| 51 | + assert.strictEqual(typeof entry.detail.service, 'string'); | ||
| 52 | + break; | ||
| 53 | + case 'queryAny': | ||
| 54 | + assert.strictEqual(typeof entry.detail.host, 'string'); | ||
| 55 | + assert.strictEqual(typeof entry.detail.ttl, 'boolean'); | ||
| 56 | + assert.strictEqual(Array.isArray(entry.detail.result), true); | ||
| 57 | + break; | ||
| 58 | + } | ||
| 25 | 59 | }); | |
| 26 | 60 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments