mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 15:41:06 +00:00

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>
27 lines
745 B
JavaScript
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');
|
|
});
|
|
});
|