2020
2121using node::kAllowedInEnvvar ;
2222using node::kDisallowedInEnvvar ;
23- using v8::AllocationProfile;
2423using v8::Array;
2524using v8::ArrayBuffer;
2625using v8::Boolean;
@@ -33,7 +32,6 @@ using v8::Float64Array;
3332using v8::FunctionCallbackInfo;
3433using v8::FunctionTemplate;
3534using v8::HandleScope;
36- using v8::HeapProfiler;
3735using v8::HeapStatistics;
3836using v8::Integer;
3937using v8::Isolate;
@@ -1087,63 +1085,6 @@ void Worker::StartHeapProfile(const FunctionCallbackInfo<Value>& args) {
10871085 }
10881086}
10891087
1090- static void buildHeapProfileNode (Isolate* isolate,
1091- const AllocationProfile::Node* node,
1092- JSONWriter* writer) {
1093- size_t selfSize = 0 ;
1094- for (const auto & allocation : node->allocations )
1095- selfSize += allocation.size * allocation.count ;
1096-
1097- writer->json_keyvalue (" selfSize" , selfSize);
1098- writer->json_keyvalue (" id" , node->node_id );
1099- writer->json_objectstart (" callFrame" );
1100- writer->json_keyvalue (" scriptId" , node->script_id );
1101- writer->json_keyvalue (" lineNumber" , node->line_number - 1 );
1102- writer->json_keyvalue (" columnNumber" , node->column_number - 1 );
1103- node::Utf8Value name (isolate, node->name );
1104- node::Utf8Value script_name (isolate, node->script_name );
1105- writer->json_keyvalue (" functionName" , *name);
1106- writer->json_keyvalue (" url" , *script_name);
1107- writer->json_objectend ();
1108-
1109- writer->json_arraystart (" children" );
1110- for (const auto * child : node->children ) {
1111- writer->json_start ();
1112- buildHeapProfileNode (isolate, child, writer);
1113- writer->json_end ();
1114- }
1115- writer->json_arrayend ();
1116- }
1117-
1118- static bool serializeProfile (Isolate* isolate, std::ostringstream& out_stream) {
1119- HandleScope scope (isolate);
1120- HeapProfiler* profiler = isolate->GetHeapProfiler ();
1121- std::unique_ptr<AllocationProfile> profile (profiler->GetAllocationProfile ());
1122- if (!profile) {
1123- return false ;
1124- }
1125- JSONWriter writer (out_stream, false );
1126- writer.json_start ();
1127-
1128- writer.json_arraystart (" samples" );
1129- for (const auto & sample : profile->GetSamples ()) {
1130- writer.json_start ();
1131- writer.json_keyvalue (" size" , sample.size * sample.count );
1132- writer.json_keyvalue (" nodeId" , sample.node_id );
1133- writer.json_keyvalue (" ordinal" , static_cast <double >(sample.sample_id ));
1134- writer.json_end ();
1135- }
1136- writer.json_arrayend ();
1137-
1138- writer.json_objectstart (" head" );
1139- buildHeapProfileNode (isolate, profile->GetRootNode (), &writer);
1140- writer.json_objectend ();
1141-
1142- writer.json_end ();
1143- profiler->StopSamplingHeapProfiler ();
1144- return true ;
1145- }
1146-
11471088void Worker::StopHeapProfile (const FunctionCallbackInfo<Value>& args) {
11481089 Worker* w;
11491090 ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
@@ -1163,7 +1104,7 @@ void Worker::StopHeapProfile(const FunctionCallbackInfo<Value>& args) {
11631104 bool scheduled = w->RequestInterrupt ([taker = std::move (taker),
11641105 env](Environment* worker_env) mutable {
11651106 std::ostringstream out_stream;
1166- bool success = serializeProfile (worker_env->isolate (), out_stream);
1107+ bool success = node::SerializeHeapProfile (worker_env->isolate (), out_stream);
11671108 env->SetImmediateThreadsafe (
11681109 [taker = std::move (taker),
11691110 out_stream = std::move (out_stream),
0 commit comments