node/test/parallel/test-dns-perf_hooks.js
theanarkh e5200392a2
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 <matteo.collina@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
2022-03-29 16:43:28 +01:00

27 lines
745 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const dns = require('dns');
const { PerformanceObserver } = require('perf_hooks');
const entries = [];
const obs = new PerformanceObserver(common.mustCallAtLeast((items) => {
entries.push(...items.getEntries());
}));
obs.observe({ type: 'dns' });
dns.lookup('localhost', () => {});
process.on('exit', () => {
assert.strictEqual(entries.length, 1);
entries.forEach((entry) => {
assert.strictEqual(!!entry.name, true);
assert.strictEqual(entry.entryType, 'dns');
assert.strictEqual(typeof entry.startTime, 'number');
assert.strictEqual(typeof entry.duration, 'number');
assert.strictEqual(typeof entry.detail, 'object');
});
});