worker.startHeapProfile()


新增于: v24.9.0, v22.20.0

启动一个堆配置文件,然后返回一个 Promise,该 Promise 会以错误或 HeapProfileHandle 对象的形式完成。此 API 支持 await using 语法。

\Starting a Heap profile then return a Promise that fulfills with an error or an HeapProfileHandle object. This API supports await using syntax.

const { Worker } = require('node:worker_threads');
const worker = new Worker(`
 const { parentPort } = require('worker_threads');
 parentPort.on('message', () => {});
 `, { eval: true });
worker.on('online', async () => {
 const handle = await worker.startHeapProfile();
 const profile = await handle.stop();
 console.log(profile);
 worker.terminate();
}); 

await using 示例。

\await using example.

const { Worker } = require('node:worker_threads');
const w = new Worker(`
 const { parentPort } = require('node: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.startHeapProfile();
}); 

AltStyle によって変換されたページ (->オリジナル) /