32 using v8::ArrayBuffer;
34 using v8::FunctionCallbackInfo;
35 using v8::HeapSpaceStatistics;
36 using v8::HeapStatistics;
40 using v8::NewStringType;
42 using v8::ScriptCompiler;
48 #define HEAP_STATISTICS_PROPERTIES(V) \ 49 V(0, total_heap_size, kTotalHeapSizeIndex) \ 50 V(1, total_heap_size_executable, kTotalHeapSizeExecutableIndex) \ 51 V(2, total_physical_size, kTotalPhysicalSizeIndex) \ 52 V(3, total_available_size, kTotalAvailableSize) \ 53 V(4, used_heap_size, kUsedHeapSizeIndex) \ 54 V(5, heap_size_limit, kHeapSizeLimitIndex) \ 55 V(6, malloced_memory, kMallocedMemoryIndex) \ 56 V(7, peak_malloced_memory, kPeakMallocedMemoryIndex) \ 57 V(8, does_zap_garbage, kDoesZapGarbageIndex) 60 static const size_t kHeapStatisticsPropertiesCount =
64 #define HEAP_SPACE_STATISTICS_PROPERTIES(V) \ 65 V(0, space_size, kSpaceSizeIndex) \ 66 V(1, space_used_size, kSpaceUsedSizeIndex) \ 67 V(2, space_available_size, kSpaceAvailableSizeIndex) \ 68 V(3, physical_space_size, kPhysicalSpaceSizeIndex) 71 static const size_t kHeapSpaceStatisticsPropertiesCount =
76 static size_t number_of_heap_spaces = 0;
80 Environment* env = Environment::GetCurrent(args);
81 Local<Integer> result =
82 Integer::NewFromUnsigned(env->isolate(),
84 args.GetReturnValue().Set(result);
89 Environment* env = Environment::GetCurrent(args);
91 env->isolate()->GetHeapStatistics(&s);
92 double*
const buffer = env->heap_statistics_buffer();
93 #define V(index, name, _) buffer[index] = static_cast<double>(s.name()); 100 Environment* env = Environment::GetCurrent(args);
101 HeapSpaceStatistics
s;
102 Isolate*
const isolate = env->isolate();
103 double* buffer = env->heap_space_statistics_buffer();
105 for (
size_t i = 0; i < number_of_heap_spaces; i++) {
106 isolate->GetHeapSpaceStatistics(&s, i);
107 size_t const property_offset = i * kHeapSpaceStatisticsPropertiesCount;
108 #define V(index, name, _) buffer[property_offset + index] = \ 109 static_cast<double>(s.name()); 117 Environment* env = Environment::GetCurrent(args);
119 if (args.Length() < 1)
120 return env->ThrowTypeError(
"v8 flag is required");
121 if (!args[0]->IsString())
122 return env->ThrowTypeError(
"v8 flag must be a string");
124 String::Utf8Value flags(args[0]);
131 Local<Context> context) {
132 Environment* env = Environment::GetCurrent(context);
136 env->SetMethod(target,
137 "updateHeapStatisticsArrayBuffer",
140 env->set_heap_statistics_buffer(
new double[kHeapStatisticsPropertiesCount]);
142 const size_t heap_statistics_buffer_byte_length =
143 sizeof(*env->heap_statistics_buffer()) * kHeapStatisticsPropertiesCount;
145 target->Set(FIXED_ONE_BYTE_STRING(env->isolate(),
146 "heapStatisticsArrayBuffer"),
148 env->heap_statistics_buffer(),
149 heap_statistics_buffer_byte_length));
151 #define V(i, _, name) \ 152 target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), #name), \ 153 Uint32::NewFromUnsigned(env->isolate(), i)); 158 target->Set(FIXED_ONE_BYTE_STRING(env->isolate(),
159 "kHeapSpaceStatisticsPropertiesCount"),
160 Uint32::NewFromUnsigned(env->isolate(),
161 kHeapSpaceStatisticsPropertiesCount));
163 number_of_heap_spaces = env->isolate()->NumberOfHeapSpaces();
167 HeapSpaceStatistics
s;
168 const Local<Array> heap_spaces =
Array::New(env->isolate(),
169 number_of_heap_spaces);
170 for (
size_t i = 0; i < number_of_heap_spaces; i++) {
171 env->isolate()->GetHeapSpaceStatistics(&s, i);
172 Local<String> heap_space_name = String::NewFromUtf8(env->isolate(),
174 NewStringType::kNormal)
176 heap_spaces->Set(i, heap_space_name);
178 target->Set(FIXED_ONE_BYTE_STRING(env->isolate(),
"kHeapSpaces"),
181 env->SetMethod(target,
182 "updateHeapSpaceStatisticsArrayBuffer",
185 env->set_heap_space_statistics_buffer(
186 new double[kHeapSpaceStatisticsPropertiesCount * number_of_heap_spaces]);
188 const size_t heap_space_statistics_buffer_byte_length =
189 sizeof(*env->heap_space_statistics_buffer()) *
190 kHeapSpaceStatisticsPropertiesCount *
191 number_of_heap_spaces;
193 target->Set(FIXED_ONE_BYTE_STRING(env->isolate(),
194 "heapSpaceStatisticsArrayBuffer"),
196 env->heap_space_statistics_buffer(),
197 heap_space_statistics_buffer_byte_length));
199 #define V(i, _, name) \ 200 target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), #name), \ 201 Uint32::NewFromUnsigned(env->isolate(), i)); void SetFlagsFromString(const FunctionCallbackInfo< Value > &args)
NODE_MODULE_CONTEXT_AWARE_BUILTIN(inspector, node::inspector::Agent::InitInspector)
void CachedDataVersionTag(const FunctionCallbackInfo< Value > &args)
#define HEAP_STATISTICS_PROPERTIES(V)
void InitializeV8Bindings(Local< Object > target, Local< Value > unused, Local< Context > context)
#define HEAP_SPACE_STATISTICS_PROPERTIES(V)
void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo< Value > &args)
MaybeLocal< Object > New(Isolate *isolate, Local< String > string, enum encoding enc)
void UpdateHeapStatisticsArrayBuffer(const FunctionCallbackInfo< Value > &args)