2 import { Readable } from "stream";
4 interface HeapSpaceInfo {
7 space_used_size: number;
8 space_available_size: number;
9 physical_space_size: number;
12 // ** Signifies if the --zap_code_space option is enabled or not. 1 == enabled, 0 == disabled. */
13 type DoesZapCodeSpaceFlag = 0 | 1;
16 total_heap_size: number;
17 total_heap_size_executable: number;
18 total_physical_size: number;
19 total_available_size: number;
20 used_heap_size: number;
21 heap_size_limit: number;
22 malloced_memory: number;
23 peak_malloced_memory: number;
24 does_zap_garbage: DoesZapCodeSpaceFlag;
25 number_of_native_contexts: number;
26 number_of_detached_contexts: number;
29 interface HeapCodeStatistics {
30 code_and_metadata_size: number;
31 bytecode_and_metadata_size: number;
32 external_script_source_size: number;
36 * Returns an integer representing a "version tag" derived from the V8 version, command line flags and detected CPU features.
37 * This is useful for determining whether a vm.Script cachedData buffer is compatible with this instance of V8.
39 function cachedDataVersionTag(): number;
41 function getHeapStatistics(): HeapInfo;
42 function getHeapSpaceStatistics(): HeapSpaceInfo[];
43 function setFlagsFromString(flags: string): void;
45 * Generates a snapshot of the current V8 heap and returns a Readable
46 * Stream that may be used to read the JSON serialized representation.
47 * This conversation was marked as resolved by joyeecheung
48 * This JSON stream format is intended to be used with tools such as
49 * Chrome DevTools. The JSON schema is undocumented and specific to the
50 * V8 engine, and may change from one version of V8 to the next.
52 function getHeapSnapshot(): Readable;
56 * @param fileName The file path where the V8 heap snapshot is to be
57 * saved. If not specified, a file name with the pattern
58 * `'Heap-${yyyymmdd}-${hhmmss}-${pid}-${thread_id}.heapsnapshot'` will be
59 * generated, where `{pid}` will be the PID of the Node.js process,
60 * `{thread_id}` will be `0` when `writeHeapSnapshot()` is called from
61 * the main Node.js thread or the id of a worker thread.
63 function writeHeapSnapshot(fileName?: string): string;
65 function getHeapCodeStatistics(): HeapCodeStatistics;
69 * Writes out a header, which includes the serialization format version.
74 * Serializes a JavaScript value and adds the serialized representation to the internal buffer.
75 * This throws an error if value cannot be serialized.
77 writeValue(val: any): boolean;
80 * Returns the stored internal buffer.
81 * This serializer should not be used once the buffer is released.
82 * Calling this method results in undefined behavior if a previous write has failed.
84 releaseBuffer(): Buffer;
87 * Marks an ArrayBuffer as having its contents transferred out of band.\
88 * Pass the corresponding ArrayBuffer in the deserializing context to deserializer.transferArrayBuffer().
90 transferArrayBuffer(id: number, arrayBuffer: ArrayBuffer): void;
93 * Write a raw 32-bit unsigned integer.
95 writeUint32(value: number): void;
98 * Write a raw 64-bit unsigned integer, split into high and low 32-bit parts.
100 writeUint64(hi: number, lo: number): void;
103 * Write a JS number value.
105 writeDouble(value: number): void;
108 * Write raw bytes into the serializer’s internal buffer.
109 * The deserializer will require a way to compute the length of the buffer.
111 writeRawBytes(buffer: NodeJS.TypedArray): void;
115 * A subclass of `Serializer` that serializes `TypedArray` (in particular `Buffer`) and `DataView` objects as host objects,
116 * and only stores the part of their underlying `ArrayBuffers` that they are referring to.
118 class DefaultSerializer extends Serializer {
122 constructor(data: NodeJS.TypedArray);
124 * Reads and validates a header (including the format version).
125 * May, for example, reject an invalid or unsupported wire format.
126 * In that case, an Error is thrown.
128 readHeader(): boolean;
131 * Deserializes a JavaScript value from the buffer and returns it.
136 * Marks an ArrayBuffer as having its contents transferred out of band.
137 * Pass the corresponding `ArrayBuffer` in the serializing context to serializer.transferArrayBuffer()
138 * (or return the id from serializer._getSharedArrayBufferId() in the case of SharedArrayBuffers).
140 transferArrayBuffer(id: number, arrayBuffer: ArrayBuffer): void;
143 * Reads the underlying wire format version.
144 * Likely mostly to be useful to legacy code reading old wire format versions.
145 * May not be called before .readHeader().
147 getWireFormatVersion(): number;
150 * Read a raw 32-bit unsigned integer and return it.
152 readUint32(): number;
155 * Read a raw 64-bit unsigned integer and return it as an array [hi, lo] with two 32-bit unsigned integer entries.
157 readUint64(): [number, number];
160 * Read a JS number value.
162 readDouble(): number;
165 * Read raw bytes from the deserializer’s internal buffer.
166 * The length parameter must correspond to the length of the buffer that was passed to serializer.writeRawBytes().
168 readRawBytes(length: number): Buffer;
172 * A subclass of `Serializer` that serializes `TypedArray` (in particular `Buffer`) and `DataView` objects as host objects,
173 * and only stores the part of their underlying `ArrayBuffers` that they are referring to.
175 class DefaultDeserializer extends Deserializer {
179 * Uses a `DefaultSerializer` to serialize value into a buffer.
181 function serialize(value: any): Buffer;
184 * Uses a `DefaultDeserializer` with default options to read a JS value from a buffer.
186 function deserialize(data: NodeJS.TypedArray): any;