diff options
author | Yuriy Vasiyarov <yvasiyarov@ozon.travel> | 2019-05-30 16:41:03 +0300 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-07-30 21:36:51 +0300 |
commit | 21a7c695f0601ae10ccf6f6cdc9f35f56be2fe90 (patch) | |
tree | c6eb8e8c1d9905727e08b0f429e821c99b94b6ca /src/node_v8.cc | |
parent | 8be37663532ac364ef57eb33913ae4ece583077d (diff) |
src: export v8.GetHeapCodeAndMetadataStatistics()
Export statistic provided by V8 through HeapCodeStatistics class and
and GetHeapCodeAndMetadataStatistics function to v8 Node.js module
PR-URL: https://github.com/nodejs/node/pull/27978
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_v8.cc')
-rw-r--r-- | src/node_v8.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/node_v8.cc b/src/node_v8.cc index 1227ebec536..9644468c4f6 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -30,6 +30,7 @@ using v8::Array; using v8::ArrayBuffer; using v8::Context; using v8::FunctionCallbackInfo; +using v8::HeapCodeStatistics; using v8::HeapSpaceStatistics; using v8::HeapStatistics; using v8::Integer; @@ -43,6 +44,7 @@ using v8::Uint32; using v8::V8; using v8::Value; + #define HEAP_STATISTICS_PROPERTIES(V) \ V(0, total_heap_size, kTotalHeapSizeIndex) \ V(1, total_heap_size_executable, kTotalHeapSizeExecutableIndex) \ @@ -61,6 +63,7 @@ static const size_t kHeapStatisticsPropertiesCount = HEAP_STATISTICS_PROPERTIES(V); #undef V + #define HEAP_SPACE_STATISTICS_PROPERTIES(V) \ V(0, space_size, kSpaceSizeIndex) \ V(1, space_used_size, kSpaceUsedSizeIndex) \ @@ -73,6 +76,16 @@ static const size_t kHeapSpaceStatisticsPropertiesCount = #undef V +#define HEAP_CODE_STATISTICS_PROPERTIES(V) \ + V(0, code_and_metadata_size, kCodeAndMetadataSizeIndex) \ + V(1, bytecode_and_metadata_size, kBytecodeAndMetadataSizeIndex) \ + V(2, external_script_source_size, kExternalScriptSourceSizeIndex) + +#define V(a, b, c) +1 +static const size_t kHeapCodeStatisticsPropertiesCount = + HEAP_CODE_STATISTICS_PROPERTIES(V); +#undef V + void CachedDataVersionTag(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); Local<Integer> result = @@ -111,6 +124,18 @@ void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo<Value>& args) { } +void UpdateHeapCodeStatisticsArrayBuffer( + const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + HeapCodeStatistics s; + env->isolate()->GetHeapCodeAndMetadataStatistics(&s); + double* const buffer = env->heap_code_statistics_buffer(); +#define V(index, name, _) buffer[index] = static_cast<double>(s.name()); + HEAP_CODE_STATISTICS_PROPERTIES(V) +#undef V +} + + void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) { CHECK(args[0]->IsString()); String::Utf8Value flags(args.GetIsolate(), args[0]); @@ -127,6 +152,7 @@ void Initialize(Local<Object> target, env->SetMethodNoSideEffect(target, "cachedDataVersionTag", CachedDataVersionTag); + // Export symbols used by v8.getHeapStatistics() env->SetMethod(target, "updateHeapStatisticsArrayBuffer", UpdateHeapStatisticsArrayBuffer); @@ -151,6 +177,35 @@ void Initialize(Local<Object> target, HEAP_STATISTICS_PROPERTIES(V) #undef V + // Export symbols used by v8.getHeapCodeStatistics() + env->SetMethod(target, + "updateHeapCodeStatisticsArrayBuffer", + UpdateHeapCodeStatisticsArrayBuffer); + + env->set_heap_code_statistics_buffer( + new double[kHeapCodeStatisticsPropertiesCount]); + + const size_t heap_code_statistics_buffer_byte_length = + sizeof(*env->heap_code_statistics_buffer()) + * kHeapCodeStatisticsPropertiesCount; + + target->Set(env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), + "heapCodeStatisticsArrayBuffer"), + ArrayBuffer::New(env->isolate(), + env->heap_code_statistics_buffer(), + heap_code_statistics_buffer_byte_length)) + .Check(); + +#define V(i, _, name) \ + target->Set(env->context(), \ + FIXED_ONE_BYTE_STRING(env->isolate(), #name), \ + Uint32::NewFromUnsigned(env->isolate(), i)).Check(); + + HEAP_CODE_STATISTICS_PROPERTIES(V) +#undef V + + // Export symbols used by v8.getHeapSpaceStatistics() target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaceStatisticsPropertiesCount"), @@ -205,6 +260,7 @@ void Initialize(Local<Object> target, HEAP_SPACE_STATISTICS_PROPERTIES(V) #undef V + // Export symbols used by v8.setFlagsFromString() env->SetMethod(target, "setFlagsFromString", SetFlagsFromString); } |