GeezerVison is showing github.com — v8: export more fields in getHeapStatistics · nodejs/node@a8eca74
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/v8.md +16-1Lines changed: 16 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -180,6 +180,9 @@ Returns an object with the following properties: | 180 | 180 | * `does_zap_garbage` {number} | 181 | 181 | * `number_of_native_contexts` {number} | 182 | 182 | * `number_of_detached_contexts` {number} | | 183 | +* `total_global_handles_size` {number} | | 184 | +* `used_global_handles_size` {number} | | 185 | +* `external_memory` {number} | 183 | 186 |
| 184 | 187 | `does_zap_garbage` is a 0/1 boolean, which signifies whether the | 185 | 188 | `--zap_code_space` option is enabled or not. This makes V8 overwrite heap | @@ -195,6 +198,15 @@ a memory leak. | 195 | 198 | of contexts that were detached and not yet garbage collected. This number | 196 | 199 | being non-zero indicates a potential memory leak. | 197 | 200 |
| | 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 array | | 208 | +buffers and external strings. | | 209 | + | 198 | 210 | <!-- eslint-skip --> | 199 | 211 |
| 200 | 212 | ```js | @@ -209,7 +221,10 @@ being non-zero indicates a potential memory leak. | 209 | 221 | peak_malloced_memory: 1127496, | 210 | 222 | does_zap_garbage: 0, | 211 | 223 | 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 | 213 | 228 | } | 214 | 229 | ``` | 215 | 230 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/v8.js +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -107,6 +107,9 @@ const { | 107 | 107 | kPeakMallocedMemoryIndex, | 108 | 108 | kNumberOfNativeContextsIndex, | 109 | 109 | kNumberOfDetachedContextsIndex, | | 110 | + kTotalGlobalHandlesSizeIndex, | | 111 | + kUsedGlobalHandlesSizeIndex, | | 112 | + kExternalMemoryIndex, | 110 | 113 |
| 111 | 114 | // Properties for heap spaces statistics buffer extraction. | 112 | 115 | kHeapSpaces, | @@ -165,7 +168,10 @@ function getHeapStatistics() { | 165 | 168 | peak_malloced_memory: buffer[kPeakMallocedMemoryIndex], | 166 | 169 | does_zap_garbage: buffer[kDoesZapGarbageIndex], | 167 | 170 | 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] | 169 | 175 | }; | 170 | 176 | } | 171 | 177 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_v8.cc +15-13Lines changed: 15 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,19 +47,21 @@ using v8::Uint32; | 47 | 47 | using v8::V8; | 48 | 48 | using v8::Value; | 49 | 49 |
| 50 | | - | 51 | | -#define HEAP_STATISTICS_PROPERTIES(V) \ | 52 | | - V(0, total_heap_size, kTotalHeapSizeIndex) \ | 53 | | - V(1, total_heap_size_executable, kTotalHeapSizeExecutableIndex) \ | 54 | | - V(2, total_physical_size, kTotalPhysicalSizeIndex) \ | 55 | | - V(3, total_available_size, kTotalAvailableSize) \ | 56 | | - V(4, used_heap_size, kUsedHeapSizeIndex) \ | 57 | | - V(5, heap_size_limit, kHeapSizeLimitIndex) \ | 58 | | - V(6, malloced_memory, kMallocedMemoryIndex) \ | 59 | | - V(7, peak_malloced_memory, kPeakMallocedMemoryIndex) \ | 60 | | - V(8, does_zap_garbage, kDoesZapGarbageIndex) \ | 61 | | - V(9, number_of_native_contexts, kNumberOfNativeContextsIndex) \ | 62 | | - V(10, number_of_detached_contexts, kNumberOfDetachedContextsIndex) | | 50 | +#define HEAP_STATISTICS_PROPERTIES(V) \ | | 51 | + V(0, total_heap_size, kTotalHeapSizeIndex) \ | | 52 | + V(1, total_heap_size_executable, kTotalHeapSizeExecutableIndex) \ | | 53 | + V(2, total_physical_size, kTotalPhysicalSizeIndex) \ | | 54 | + V(3, total_available_size, kTotalAvailableSize) \ | | 55 | + V(4, used_heap_size, kUsedHeapSizeIndex) \ | | 56 | + V(5, heap_size_limit, kHeapSizeLimitIndex) \ | | 57 | + V(6, malloced_memory, kMallocedMemoryIndex) \ | | 58 | + V(7, peak_malloced_memory, kPeakMallocedMemoryIndex) \ | | 59 | + V(8, does_zap_garbage, kDoesZapGarbageIndex) \ | | 60 | + V(9, number_of_native_contexts, kNumberOfNativeContextsIndex) \ | | 61 | + V(10, number_of_detached_contexts, kNumberOfDetachedContextsIndex) \ | | 62 | + V(11, total_global_handles_size, kTotalGlobalHandlesSizeIndex) \ | | 63 | + V(12, used_global_handles_size, kUsedGlobalHandlesSizeIndex) \ | | 64 | + V(13, external_memory, kExternalMemoryIndex) | 63 | 65 |
| 64 | 66 | #define V(a, b, c) +1 | 65 | 67 | static constexpr size_t kHeapStatisticsPropertiesCount = | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-v8-stats.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,15 +6,18 @@ const v8 = require('v8'); | 6 | 6 | const s = v8.getHeapStatistics(); | 7 | 7 | const keys = [ | 8 | 8 | 'does_zap_garbage', | | 9 | + 'external_memory', | 9 | 10 | 'heap_size_limit', | 10 | 11 | 'malloced_memory', | 11 | 12 | 'number_of_detached_contexts', | 12 | 13 | 'number_of_native_contexts', | 13 | 14 | 'peak_malloced_memory', | 14 | 15 | 'total_available_size', | | 16 | + 'total_global_handles_size', | 15 | 17 | 'total_heap_size', | 16 | 18 | 'total_heap_size_executable', | 17 | 19 | 'total_physical_size', | | 20 | + 'used_global_handles_size', | 18 | 21 | 'used_heap_size']; | 19 | 22 | assert.deepStrictEqual(Object.keys(s).sort(), keys); | 20 | 23 | keys.forEach(function(key) { | |
|