Skip to content

Commit

Permalink
v8: export more fields in getHeapStatistics
Browse files Browse the repository at this point in the history
export total_global_handles_size, used_global_handles_size,
external_memory in getHeapStatistics
  • Loading branch information
theanarkh committed Apr 19, 2022
1 parent 77373aa commit 67dfc51
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion doc/api/v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ Returns an object with the following properties:
* `does_zap_garbage` {number}
* `number_of_native_contexts` {number}
* `number_of_detached_contexts` {number}
* `total_global_handles_size` {number}
* `used_global_handles_size` {number}
* `external_memory` {number}

`does_zap_garbage` is a 0/1 boolean, which signifies whether the
`--zap_code_space` option is enabled or not. This makes V8 overwrite heap
Expand Down Expand Up @@ -209,7 +212,10 @@ being non-zero indicates a potential memory leak.
peak_malloced_memory: 1127496,
does_zap_garbage: 0,
number_of_native_contexts: 1,
number_of_detached_contexts: 0
number_of_detached_contexts: 0,
total_global_handles_size: 8192,
used_global_handles_size: 3296,
external_memory: 318824
}
```

Expand Down
8 changes: 7 additions & 1 deletion lib/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ const {
kPeakMallocedMemoryIndex,
kNumberOfNativeContextsIndex,
kNumberOfDetachedContextsIndex,
kTotalGlobalHandlesSizeIndex,
kUsedGlobalHandlesSizeIndex,
kExternalMemoryIndex,

// Properties for heap spaces statistics buffer extraction.
kHeapSpaces,
Expand Down Expand Up @@ -165,7 +168,10 @@ function getHeapStatistics() {
peak_malloced_memory: buffer[kPeakMallocedMemoryIndex],
does_zap_garbage: buffer[kDoesZapGarbageIndex],
number_of_native_contexts: buffer[kNumberOfNativeContextsIndex],
number_of_detached_contexts: buffer[kNumberOfDetachedContextsIndex]
number_of_detached_contexts: buffer[kNumberOfDetachedContextsIndex],
total_global_handles_size: buffer[kTotalGlobalHandlesSizeIndex],
used_global_handles_size: buffer[kUsedGlobalHandlesSizeIndex],
external_memory: buffer[kExternalMemoryIndex]
};
}

Expand Down
5 changes: 4 additions & 1 deletion src/node_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ using v8::Value;
V(7, peak_malloced_memory, kPeakMallocedMemoryIndex) \
V(8, does_zap_garbage, kDoesZapGarbageIndex) \
V(9, number_of_native_contexts, kNumberOfNativeContextsIndex) \
V(10, number_of_detached_contexts, kNumberOfDetachedContextsIndex)
V(10, number_of_detached_contexts, kNumberOfDetachedContextsIndex) \
V(11, total_global_handles_size, kTotalGlobalHandlesSizeIndex) \
V(12, used_global_handles_size, kUsedGlobalHandlesSizeIndex) \
V(13, external_memory, kExternalMemoryIndex)

#define V(a, b, c) +1
static constexpr size_t kHeapStatisticsPropertiesCount =
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-v8-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ const v8 = require('v8');
const s = v8.getHeapStatistics();
const keys = [
'does_zap_garbage',
'external_memory',
'heap_size_limit',
'malloced_memory',
'number_of_detached_contexts',
'number_of_native_contexts',
'peak_malloced_memory',
'total_available_size',
'total_global_handles_size',
'total_heap_size',
'total_heap_size_executable',
'total_physical_size',
'used_global_handles_size',
'used_heap_size'];
assert.deepStrictEqual(Object.keys(s).sort(), keys);
keys.forEach(function(key) {
Expand Down

0 comments on commit 67dfc51

Please sign in to comment.