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;
@@ -1086,63 +1084,6 @@ void Worker::StartHeapProfile(const FunctionCallbackInfo<Value>& args) {
10861084 }
10871085}
10881086
1089- static void buildHeapProfileNode (Isolate* isolate,
1090- const AllocationProfile::Node* node,
1091- JSONWriter* writer) {
1092- size_t selfSize = 0 ;
1093- for (const auto & allocation : node->allocations )
1094- selfSize += allocation.size * allocation.count ;
1095-
1096- writer->json_keyvalue (" selfSize" , selfSize);
1097- writer->json_keyvalue (" id" , node->node_id );
1098- writer->json_objectstart (" callFrame" );
1099- writer->json_keyvalue (" scriptId" , node->script_id );
1100- writer->json_keyvalue (" lineNumber" , node->line_number - 1 );
1101- writer->json_keyvalue (" columnNumber" , node->column_number - 1 );
1102- node::Utf8Value name (isolate, node->name );
1103- node::Utf8Value script_name (isolate, node->script_name );
1104- writer->json_keyvalue (" functionName" , *name);
1105- writer->json_keyvalue (" url" , *script_name);
1106- writer->json_objectend ();
1107-
1108- writer->json_arraystart (" children" );
1109- for (const auto * child : node->children ) {
1110- writer->json_start ();
1111- buildHeapProfileNode (isolate, child, writer);
1112- writer->json_end ();
1113- }
1114- writer->json_arrayend ();
1115- }
1116-
1117- static bool serializeProfile (Isolate* isolate, std::ostringstream& out_stream) {
1118- HandleScope scope (isolate);
1119- HeapProfiler* profiler = isolate->GetHeapProfiler ();
1120- std::unique_ptr<AllocationProfile> profile (profiler->GetAllocationProfile ());
1121- if (!profile) {
1122- return false ;
1123- }
1124- profiler->StopSamplingHeapProfiler ();
1125- JSONWriter writer (out_stream, true );
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- return true ;
1144- }
1145-
11461087void Worker::StopHeapProfile (const FunctionCallbackInfo<Value>& args) {
11471088 Worker* w;
11481089 ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
@@ -1162,7 +1103,8 @@ void Worker::StopHeapProfile(const FunctionCallbackInfo<Value>& args) {
11621103 bool scheduled = w->RequestInterrupt ([taker = std::move (taker),
11631104 env](Environment* worker_env) mutable {
11641105 std::ostringstream out_stream;
1165- bool success = serializeProfile (worker_env->isolate (), out_stream);
1106+ bool success =
1107+ node::SerializeHeapProfile (worker_env->isolate (), out_stream);
11661108 env->SetImmediateThreadsafe (
11671109 [taker = std::move (taker),
11681110 out_stream = std::move (out_stream),
0 commit comments