Skip to content

Commit 1abd520

Browse files
committed
v8: export more fields in getHeapStatistics
export total_global_handles_size, used_global_handles_size, external_memory in getHeapStatistics
1 parent fe85cf7 commit 1abd520

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

doc/api/v8.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ Returns an object with the following properties:
180180
* `does_zap_garbage` {number}
181181
* `number_of_native_contexts` {number}
182182
* `number_of_detached_contexts` {number}
183+
* `total_global_handles_size` {number}
184+
* `used_global_handles_size` {number}
185+
* `external_memory` {number}
183186

184187
`does_zap_garbage` is a 0/1 boolean, which signifies whether the
185188
`--zap_code_space` option is enabled or not. This makes V8 overwrite heap
@@ -195,6 +198,15 @@ a memory leak.
195198
of contexts that were detached and not yet garbage collected. This number
196199
being non-zero indicates a potential memory leak.
197200

201+
`total_global_handles_size` The value of total\_global\_handles\_size is the
202+
total memory size of V8 global handles.
203+
204+
`used_global_handles_size` The value of used\_global\_handles\_size is the
205+
used memory size of V8 global handles.
206+
207+
`external_memory` The value of external\_memory is the memory size of
208+
array buffers and external strings.
209+
198210
<!-- eslint-skip -->
199211

200212
```js
@@ -209,7 +221,10 @@ being non-zero indicates a potential memory leak.
209221
peak_malloced_memory: 1127496,
210222
does_zap_garbage: 0,
211223
number_of_native_contexts: 1,
212-
number_of_detached_contexts: 0
224+
number_of_detached_contexts: 0,
225+
total_global_handles_size: 8192,
226+
used_global_handles_size: 3296,
227+
external_memory: 318824
213228
}
214229
```
215230

lib/v8.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ const {
107107
kPeakMallocedMemoryIndex,
108108
kNumberOfNativeContextsIndex,
109109
kNumberOfDetachedContextsIndex,
110+
kTotalGlobalHandlesSizeIndex,
111+
kUsedGlobalHandlesSizeIndex,
112+
kExternalMemoryIndex,
110113

111114
// Properties for heap spaces statistics buffer extraction.
112115
kHeapSpaces,
@@ -165,7 +168,10 @@ function getHeapStatistics() {
165168
peak_malloced_memory: buffer[kPeakMallocedMemoryIndex],
166169
does_zap_garbage: buffer[kDoesZapGarbageIndex],
167170
number_of_native_contexts: buffer[kNumberOfNativeContextsIndex],
168-
number_of_detached_contexts: buffer[kNumberOfDetachedContextsIndex]
171+
number_of_detached_contexts: buffer[kNumberOfDetachedContextsIndex],
172+
total_global_handles_size: buffer[kTotalGlobalHandlesSizeIndex],
173+
used_global_handles_size: buffer[kUsedGlobalHandlesSizeIndex],
174+
external_memory: buffer[kExternalMemoryIndex]
169175
};
170176
}
171177

src/node_v8.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ using v8::Value;
5959
V(7, peak_malloced_memory, kPeakMallocedMemoryIndex) \
6060
V(8, does_zap_garbage, kDoesZapGarbageIndex) \
6161
V(9, number_of_native_contexts, kNumberOfNativeContextsIndex) \
62-
V(10, number_of_detached_contexts, kNumberOfDetachedContextsIndex)
62+
V(10, number_of_detached_contexts, kNumberOfDetachedContextsIndex) \
63+
V(11, total_global_handles_size, kTotalGlobalHandlesSizeIndex) \
64+
V(12, used_global_handles_size, kUsedGlobalHandlesSizeIndex) \
65+
V(13, external_memory, kExternalMemoryIndex)
6366

6467
#define V(a, b, c) +1
6568
static constexpr size_t kHeapStatisticsPropertiesCount =

test/parallel/test-v8-stats.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ const v8 = require('v8');
66
const s = v8.getHeapStatistics();
77
const keys = [
88
'does_zap_garbage',
9+
'external_memory',
910
'heap_size_limit',
1011
'malloced_memory',
1112
'number_of_detached_contexts',
1213
'number_of_native_contexts',
1314
'peak_malloced_memory',
1415
'total_available_size',
16+
'total_global_handles_size',
1517
'total_heap_size',
1618
'total_heap_size_executable',
1719
'total_physical_size',
20+
'used_global_handles_size',
1821
'used_heap_size'];
1922
assert.deepStrictEqual(Object.keys(s).sort(), keys);
2023
keys.forEach(function(key) {

0 commit comments

Comments
 (0)