-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src,lib: add performance.uvMetricsInfo
This commit exposes a new API to the perf_hooks.performance module. This wraps uv_metrics_info into performance.uvMetricsInfo() function. PR-URL: #54413 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
- Loading branch information
Showing
6 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Enforcing strict checks on the order or number of events across different | ||
// platforms can be tricky and unreliable due to various factors. | ||
// As a result, this test relies on the `uv_metrics_info` call instead. | ||
const { performance } = require('node:perf_hooks'); | ||
const assert = require('node:assert'); | ||
const fs = require('node:fs'); | ||
const { nodeTiming } = performance; | ||
|
||
function safeMetricsInfo(cb) { | ||
setImmediate(() => { | ||
const info = nodeTiming.uvMetricsInfo; | ||
cb(info); | ||
}); | ||
} | ||
|
||
{ | ||
const info = nodeTiming.uvMetricsInfo; | ||
assert.strictEqual(info.loopCount, 0); | ||
assert.strictEqual(info.events, 0); | ||
// This is the only part of the test that we test events waiting | ||
// Adding checks for this property will make the test flaky | ||
// as it can be highly influenced by race conditions. | ||
assert.strictEqual(info.eventsWaiting, 0); | ||
} | ||
|
||
{ | ||
// The synchronous call should obviously not affect the uv metrics | ||
const fd = fs.openSync(__filename, 'r'); | ||
fs.readFileSync(fd); | ||
const info = nodeTiming.uvMetricsInfo; | ||
assert.strictEqual(info.loopCount, 0); | ||
assert.strictEqual(info.events, 0); | ||
assert.strictEqual(info.eventsWaiting, 0); | ||
} | ||
|
||
{ | ||
function openFile(info) { | ||
assert.strictEqual(info.loopCount, 1); | ||
|
||
fs.open(__filename, 'r', (err) => { | ||
assert.ifError(err); | ||
}); | ||
} | ||
|
||
safeMetricsInfo(openFile); | ||
} |
20 changes: 20 additions & 0 deletions
20
test/parallel/test-performance-nodetiming-uvmetricsinfo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
common.skipIfWorker(); | ||
|
||
const { spawnSync } = require('node:child_process'); | ||
const assert = require('node:assert'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const file = fixtures.path('test-nodetiming-uvmetricsinfo.js'); | ||
|
||
{ | ||
const { status, stderr } = spawnSync( | ||
process.execPath, | ||
[ | ||
file, | ||
], | ||
); | ||
assert.strictEqual(status, 0, stderr.toString()); | ||
} |