-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src,lib: add performance.uvMetricsInfo #54413
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
95d36a3
src,lib: add performance.uvMetricsInfo
RafaelGSS 1861bb2
fixup! src,lib: add performance.uvMetricsInfo
RafaelGSS 85dbd8f
fixup! add mjs doc
RafaelGSS aa4dc99
fixup! apply cr suggestions
RafaelGSS c1385ed
fixup! use performance.nodeTiming instead
RafaelGSS 856d4ae
fixup! fixup! use performance.nodeTiming instead
RafaelGSS 13fe044
fixup! fixup! fixup! use performance.nodeTiming instead
RafaelGSS 391ce64
fixup! add a comment for the test guarantees
RafaelGSS 0e9cf0e
fixup! fixup! add a comment for the test guarantees
RafaelGSS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
74 changes: 74 additions & 0 deletions
74
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,74 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const fixtures = require('../common/fixtures'); | ||
|
||
const filepath = fixtures.path('x.txt'); | ||
|
||
const assert = require('node:assert'); | ||
const fs = require('node:fs'); | ||
const { performance } = require('node:perf_hooks'); | ||
|
||
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(filepath, '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); | ||
// 1. ? event | ||
assert.strictEqual(info.events, 1); | ||
|
||
fs.open(filepath, 'r', (err) => { | ||
assert.ifError(err); | ||
safeMetricsInfo(afterOpenFile); | ||
}); | ||
} | ||
|
||
function afterOpenFile(info) { | ||
assert.strictEqual(info.loopCount, 2); | ||
// 1. ? event | ||
// 2. uv_fs_open | ||
assert.strictEqual(info.events, 2); | ||
|
||
fs.readFile(filepath, (err) => { | ||
assert.ifError(err); | ||
safeMetricsInfo(afterReadFile); | ||
}); | ||
} | ||
|
||
function afterReadFile(info) { | ||
assert.strictEqual(info.loopCount, 6); | ||
// 1. ? event | ||
assert.strictEqual(info.events, 6); | ||
// 1. ? | ||
} | ||
|
||
safeMetricsInfo(openFile); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note for the future optimization: maybe we should use a buffer to store these values to avoid creating and returning js objects from c++.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I have plans to return a typed array and build the object in JS land. I'll do it in a follow up PR.