温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/v8/writeHeapSnapshot
点击访问原文链接

Node v8.writeHeapSnapshot function | API Reference | Bun

Node v8.writeHeapSnapshot function | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:v8/writeHeapSnapshotFwriteHeapSnapshot

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:v8/writeHeapSnapshotFwriteHeapSnapshot

function

v8.writeHeapSnapshot { console.log(`worker heapdump: ${filename}`); // Now get a heapdump for the main thread. console.log(`main thread heapdump: ${writeHeapSnapshot()}`); }); // Tell the worker to create a heapdump. worker.postMessage('heapdump'); } else { parentPort.once('message', (message) => { if (message === 'heapdump') { // Generate a heapdump for the worker // and return the filename to the parent. parentPort.postMessage(writeHeapSnapshot()); } }); } ```" data-algolia-static="false" data-algolia-merged="false" data-type="Function">function writeHeapSnapshot(filename?: string,options?: HeapSnapshotOptions): string;

Generates a snapshot of the current V8 heap and writes it to a JSON file. This file is intended to be used with tools such as Chrome DevTools. The JSON schema is undocumented and specific to the V8 engine, and may change from one version of V8 to the next.

A heap snapshot is specific to a single V8 isolate. When using worker threads, a heap snapshot generated from the main thread will not contain any information about the workers, and vice versa.

Creating a heap snapshot requires memory about twice the size of the heap at the time the snapshot is created. This results in the risk of OOM killers terminating the process.

Generating a snapshot is a synchronous operation which blocks the event loop for a duration depending on the heap size.

import { writeHeapSnapshot } from 'node:v8';
import {
Worker,
isMainThread,
parentPort,
} from 'node:worker_threads';

if (isMainThread) {
const worker = new Worker(__filename);

worker.once('message', (filename) => {
console.log(`worker heapdump: ${filename}`);
// Now get a heapdump for the main thread.
console.log(`main thread heapdump: ${writeHeapSnapshot()}`);
});

// Tell the worker to create a heapdump.
worker.postMessage('heapdump');
} else {
parentPort.once('message', (message) => {
if (message === 'heapdump') {
// Generate a heapdump for the worker
// and return the filename to the parent.
parentPort.postMessage(writeHeapSnapshot());
}
});
}
@param filename

The file path where the V8 heap snapshot is to be saved. If not specified, a file name with the pattern 'Heap-${yyyymmdd}-${hhmmss}-${pid}-${thread_id}.heapsnapshot' will be generated, where {pid} will be the PID of the Node.js process, {thread_id} will be 0 when writeHeapSnapshot() is called from the main Node.js thread or the id of a worker thread.

@returns

The filename where the snapshot was saved.

Referenced typesinterface HeapSnapshotOptionsexposeInternals?: boolean

If true, expose internals in the heap snapshot.

exposeNumericValues?: boolean

If true, expose numeric values in artificial fields.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Node v8.writeHeapSnapshot function | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for function node:v8.writeHeapSnapshot | Bun