-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
worker: optimize cpu profile implement #59683
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1958,19 +1958,16 @@ this matches its values. | |
|
||
If the worker has stopped, the return value is an empty object. | ||
|
||
### `worker.startCpuProfile(name)` | ||
### `worker.startCpuProfile()` | ||
|
||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
* name: {string} | ||
* Returns: {Promise} | ||
|
||
Starting a CPU profile with the given `name`, then return a Promise that fulfills | ||
with an error or an object which has a `stop` method. Calling the `stop` method will | ||
stop collecting the profile, then return a Promise that fulfills with an error or the | ||
profile data. | ||
Starting a CPU profile then return a Promise that fulfills with an error | ||
or an `CPUProfileHandle` object. This API supports `await using` syntax. | ||
|
||
```cjs | ||
const { Worker } = require('node:worker_threads'); | ||
|
@@ -1981,13 +1978,29 @@ const worker = new Worker(` | |
`, { eval: true }); | ||
|
||
worker.on('online', async () => { | ||
const handle = await worker.startCpuProfile('demo'); | ||
const handle = await worker.startCpuProfile(); | ||
const profile = await handle.stop(); | ||
console.log(profile); | ||
worker.terminate(); | ||
}); | ||
``` | ||
|
||
`await using` example. | ||
|
||
```cjs | ||
const { Worker } = require('node::worker_threads'); | ||
|
||
const w = new Worker(` | ||
const { parentPort } = require('worker_threads'); | ||
parentPort.on('message', () => {}); | ||
`, { eval: true }); | ||
|
||
w.on('online', async () => { | ||
// Stop profile automatically when return and profile will be discarded | ||
await using handle = await w.startCpuProfile(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this example useful that it only starts the profiler, but not consumes the result? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example just demonstrates how to use |
||
}); | ||
``` | ||
|
||
### `worker.stderr` | ||
|
||
<!-- YAML | ||
|
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.
Note that if this PR does not land before the original version of the API goes out in a release this will be a semver-major change since the API was was originally landed as experimental.
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.
You mean this two PRs should be merged into
main
branch before next version release ?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, if the previous iteration happens to go out in the next release before this lands, the api changes made here would qualify it as a semver-major, so we want to avoid that.
Alternatively, we might want to mark this additional experimental just in case we need to make additional changes.
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.
The PR have been mereged. Thanks for your suggestions.