Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: export number_of_native_contexts and number_of_detached_contexts #27933

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion doc/api/v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,24 @@ Returns an object with the following properties:
* `malloced_memory` {number}
* `peak_malloced_memory` {number}
* `does_zap_garbage` {number}
* `number_of_native_contexts` {number}
* `number_of_detached_contexts` {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
garbage with a bit pattern. The RSS footprint (resident memory set) gets bigger
because it continuously touches all heap pages and that makes them less likely
to get swapped out by the operating system.

`number_of_native_contexts` The value of native_context is the number of the
top-level contexts currently active. Increase of this number over time indicates
a memory leak.

`number_of_detached_contexts` The value of detached_context is the number
of contexts that were detached and not yet garbage collected. This number
being non-zero indicates potential memory leak.
yvasiyarov marked this conversation as resolved.
Show resolved Hide resolved

<!-- eslint-skip -->
```js
{
Expand All @@ -149,7 +160,9 @@ to get swapped out by the operating system.
heap_size_limit: 1535115264,
malloced_memory: 16384,
peak_malloced_memory: 1127496,
does_zap_garbage: 0
does_zap_garbage: 0,
number_of_native_contexts: 1,
number_of_detached_contexts: 0
}
```

Expand Down
8 changes: 6 additions & 2 deletions lib/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ const {
kSpaceSizeIndex,
kSpaceUsedSizeIndex,
kSpaceAvailableSizeIndex,
kPhysicalSpaceSizeIndex
kPhysicalSpaceSizeIndex,
kNumberOfNativeContextsIndex,
kNumberOfDetachedContextsIndex
} = internalBinding('v8');

const kNumberOfHeapSpaces = kHeapSpaces.length;
Expand Down Expand Up @@ -139,7 +141,9 @@ function getHeapStatistics() {
'heap_size_limit': buffer[kHeapSizeLimitIndex],
'malloced_memory': buffer[kMallocedMemoryIndex],
'peak_malloced_memory': buffer[kPeakMallocedMemoryIndex],
'does_zap_garbage': buffer[kDoesZapGarbageIndex]
'does_zap_garbage': buffer[kDoesZapGarbageIndex],
'number_of_native_contexts': buffer[kNumberOfNativeContextsIndex],
'number_of_detached_contexts': buffer[kNumberOfDetachedContextsIndex]
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/node_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ using v8::Value;
V(5, heap_size_limit, kHeapSizeLimitIndex) \
V(6, malloced_memory, kMallocedMemoryIndex) \
V(7, peak_malloced_memory, kPeakMallocedMemoryIndex) \
V(8, does_zap_garbage, kDoesZapGarbageIndex)
V(8, does_zap_garbage, kDoesZapGarbageIndex) \
V(9, number_of_native_contexts, kNumberOfNativeContextsIndex) \
V(10, number_of_detached_contexts, kNumberOfDetachedContextsIndex)

#define V(a, b, c) +1
static const size_t kHeapStatisticsPropertiesCount =
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-v8-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const keys = [
'does_zap_garbage',
'heap_size_limit',
'malloced_memory',
'number_of_detached_contexts',
'number_of_native_contexts',
'peak_malloced_memory',
'total_available_size',
'total_heap_size',
Expand Down