worker: add cpuUsage for worker

PR-URL: https://github.com/nodejs/node/pull/59177
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com>
This commit is contained in:
theanarkh 2025-07-28 18:42:44 +08:00 committed by GitHub
parent 0bbe7c36c9
commit 0ba6e0d7ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 225 additions and 1 deletions

View file

@ -1760,6 +1760,19 @@ added: v10.5.0
The `'online'` event is emitted when the worker thread has started executing
JavaScript code.
### `worker.cpuUsage([prev])`
<!-- YAML
added:
- REPLACEME
-->
* Returns: {Promise}
This method returns a `Promise` that will resolve to an object identical to [`process.threadCpuUsage()`][],
or reject with an [`ERR_WORKER_NOT_RUNNING`][] error if the worker is no longer running.
This methods allows the statistics to be observed from outside the actual thread.
### `worker.getHeapSnapshot([options])`
<!-- YAML
@ -2123,6 +2136,7 @@ thread spawned will spawn another until the application crashes.
[`process.stderr`]: process.md#processstderr
[`process.stdin`]: process.md#processstdin
[`process.stdout`]: process.md#processstdout
[`process.threadCpuUsage()`]: process.md#processthreadcpuusagepreviousvalue
[`process.title`]: process.md#processtitle
[`require('node:worker_threads').isMainThread`]: #workerismainthread
[`require('node:worker_threads').parentPort.on('message')`]: #event-message