From b71a8107c0be0009f65b2ae717ea607a7d642685 Mon Sep 17 00:00:00 2001 From: theanarkh <2923878201@qq.com> Date: Tue, 29 Mar 2022 23:43:28 +0800 Subject: [PATCH] net,dns: trace tcp connection and dns by perf_hooks use the perf_hooks to trace the time spent by net.connect, dns.lookup, dns.lookupService, dns.resolvexxx. PR-URL: https://github.com/nodejs/node/pull/42390 Reviewed-By: Matteo Collina Reviewed-By: Paolo Insogna Reviewed-By: Mohammed Keyvanzadeh --- doc/api/perf_hooks.md | 60 ++++++++++++++++++++++++++++ lib/dns.js | 40 ++++++++++++++++++- lib/internal/dns/promises.js | 41 +++++++++++++++++++ lib/internal/perf/observe.js | 34 ++++++++++++++++ lib/net.js | 10 ++++- src/node_perf_common.h | 4 +- test/parallel/test-dns-perf_hooks.js | 26 ++++++++++++ test/parallel/test-net-perf_hooks.js | 60 ++++++++++++++++++++++++++++ 8 files changed, 272 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-dns-perf_hooks.js create mode 100644 test/parallel/test-net-perf_hooks.js diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index cba0b671ab90b0..adb535bd482d4d 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -531,6 +531,30 @@ When `performanceEntry.type` is equal to `'function'`, the `performanceEntry.detail` property will be an {Array} listing the input arguments to the timed function. +### Net ('net') Details + +When `performanceEntry.type` is equal to `'net'`, the +`performanceEntry.detail` property will be an {Object} containing +additional information. + +If `performanceEntry.name` is equal to `connect`, the `detail` +will contain the following properties: `host`, `port`. + +### DNS ('dns') Details + +When `performanceEntry.type` is equal to `'dns'`, the +`performanceEntry.detail` property will be an {Object} containing +additional information. + +If `performanceEntry.name` is equal to `lookup`, the `detail` +will contain the following properties: `hostname`, `family`, `hints`, `verbatim`. + +If `performanceEntry.name` is equal to `lookupService`, the `detail` will +contain the following properties: `host`, `port`. + +If `performanceEntry.name` is equal to `queryxxx` or `getHostByAddr`, the `detail` will +contain the following properties: `host`, `ttl`. + ## Class: `PerformanceNodeTiming`