diff --git a/doc/api/v8.md b/doc/api/v8.md index 6945f1bca085d9..ace8ea2d261d25 100644 --- a/doc/api/v8.md +++ b/doc/api/v8.md @@ -197,6 +197,7 @@ Returns an object with the following properties: * `total_global_handles_size` {number} * `used_global_handles_size` {number} * `external_memory` {number} +* `total_allocated_bytes` {number} `total_heap_size` The value of total\_heap\_size is the number of bytes V8 has allocated for the heap. This can grow if used\_heap needs more memory. @@ -250,6 +251,9 @@ used memory size of V8 global handles. `external_memory` The value of external\_memory is the memory size of array buffers and external strings. +`total_allocated_bytes` The value of total allocated bytes since the Isolate +creation + ```js diff --git a/lib/v8.js b/lib/v8.js index 47f694103719aa..54395945aa1787 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -136,6 +136,7 @@ const { kTotalGlobalHandlesSizeIndex, kUsedGlobalHandlesSizeIndex, kExternalMemoryIndex, + kTotalAllocatedBytes, // Properties for heap spaces statistics buffer extraction. kHeapSpaces, @@ -246,6 +247,7 @@ function getHeapStatistics() { total_global_handles_size: buffer[kTotalGlobalHandlesSizeIndex], used_global_handles_size: buffer[kUsedGlobalHandlesSizeIndex], external_memory: buffer[kExternalMemoryIndex], + total_allocated_bytes: buffer[kTotalAllocatedBytes], }; } diff --git a/src/node_v8.cc b/src/node_v8.cc index 935ea2cf5157c3..0a0554d01f79af 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -73,7 +73,8 @@ using v8::Value; 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) + V(13, external_memory, kExternalMemoryIndex) \ + V(14, total_allocated_bytes, kTotalAllocatedBytes) #define V(a, b, c) +1 static constexpr size_t kHeapStatisticsPropertiesCount = diff --git a/src/node_worker.cc b/src/node_worker.cc index 8d878855706ac1..d8cad06cd0655f 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -1263,6 +1263,7 @@ void Worker::GetHeapStatistics(const FunctionCallbackInfo& args) { "total_global_handles_size", "used_global_handles_size", "external_memory", + "total_allocated_bytes", }; tmpl = DictionaryTemplate::New(isolate, heap_stats_names); env->set_heap_statistics_template(tmpl); @@ -1283,7 +1284,8 @@ void Worker::GetHeapStatistics(const FunctionCallbackInfo& args) { Number::New(isolate, heap_stats->number_of_detached_contexts()), Number::New(isolate, heap_stats->total_global_handles_size()), Number::New(isolate, heap_stats->used_global_handles_size()), - Number::New(isolate, heap_stats->external_memory())}; + Number::New(isolate, heap_stats->external_memory()), + Number::New(isolate, heap_stats->total_allocated_bytes())}; Local obj; if (!NewDictionaryInstanceNullProto( diff --git a/test/parallel/test-v8-stats.js b/test/parallel/test-v8-stats.js index 07be833e6e749a..5ee4c5aeb31adf 100644 --- a/test/parallel/test-v8-stats.js +++ b/test/parallel/test-v8-stats.js @@ -12,6 +12,7 @@ const keys = [ 'number_of_detached_contexts', 'number_of_native_contexts', 'peak_malloced_memory', + 'total_allocated_bytes', 'total_available_size', 'total_global_handles_size', 'total_heap_size', diff --git a/test/parallel/test-worker-heap-statistics.js b/test/parallel/test-worker-heap-statistics.js index 12a748c303a026..ba3165aa24aba0 100644 --- a/test/parallel/test-worker-heap-statistics.js +++ b/test/parallel/test-worker-heap-statistics.js @@ -40,6 +40,7 @@ if (isMainThread) { `total_global_handles_size`, `used_global_handles_size`, `external_memory`, + `total_allocated_bytes`, ].sort(); assert.deepStrictEqual(keys, Object.keys(stats).sort()); for (const key of keys) {