@@ -812,6 +812,68 @@ void Worker::Unref(const FunctionCallbackInfo<Value>& args) {
812
812
}
813
813
}
814
814
815
+ void Worker::GetHeapStatistics (const FunctionCallbackInfo<Value>& args) {
816
+ Worker* w;
817
+ ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
818
+
819
+ v8::HeapStatistics heap_stats;
820
+ w->isolate_ ->GetHeapStatistics (&heap_stats);
821
+
822
+ auto * isolate = args.GetIsolate ();
823
+ Local<Context> currentContext = isolate->GetCurrentContext ();
824
+
825
+ Local<Object> stats = Object::New (isolate);
826
+
827
+ stats->Set (currentContext,
828
+ String::NewFromUtf8 (isolate, " total_heap_size" ).ToLocalChecked (),
829
+ Number::New (isolate, heap_stats.total_heap_size ()));
830
+ stats->Set (currentContext,
831
+ String::NewFromUtf8 (isolate, " total_heap_size_executable" )
832
+ .ToLocalChecked (),
833
+ Number::New (isolate, heap_stats.total_heap_size_executable ()));
834
+ stats->Set (currentContext,
835
+ String::NewFromUtf8 (isolate, " total_physical_size" ).ToLocalChecked (),
836
+ Number::New (isolate, heap_stats.total_physical_size ()));
837
+ stats->Set (currentContext,
838
+ String::NewFromUtf8 (isolate, " total_available_size" ).ToLocalChecked (),
839
+ Number::New (isolate, heap_stats.total_available_size ()));
840
+ stats->Set (currentContext,
841
+ String::NewFromUtf8 (isolate, " used_heap_size" ).ToLocalChecked (),
842
+ Number::New (isolate, heap_stats.used_heap_size ()));
843
+ stats->Set (currentContext,
844
+ String::NewFromUtf8 (isolate, " heap_size_limit" ).ToLocalChecked (),
845
+ Number::New (isolate, heap_stats.heap_size_limit ()));
846
+ stats->Set (currentContext,
847
+ String::NewFromUtf8 (isolate, " malloced_memory" ).ToLocalChecked (),
848
+ Number::New (isolate, heap_stats.malloced_memory ()));
849
+ stats->Set (currentContext,
850
+ String::NewFromUtf8 (isolate, " peak_malloced_memory" ).ToLocalChecked (),
851
+ Number::New (isolate, heap_stats.peak_malloced_memory ()));
852
+ stats->Set (currentContext,
853
+ String::NewFromUtf8 (isolate, " does_zap_garbage" ).ToLocalChecked (),
854
+ Boolean::New (isolate, heap_stats.does_zap_garbage ()));
855
+ stats->Set (currentContext,
856
+ String::NewFromUtf8 (isolate, " number_of_native_contexts" )
857
+ .ToLocalChecked (),
858
+ Number::New (isolate, heap_stats.number_of_native_contexts ()));
859
+ stats->Set (currentContext,
860
+ String::NewFromUtf8 (isolate, " number_of_detached_contexts" )
861
+ .ToLocalChecked (),
862
+ Number::New (isolate, heap_stats.number_of_detached_contexts ()));
863
+ stats->Set (currentContext,
864
+ String::NewFromUtf8 (isolate, " total_global_handles_size" )
865
+ .ToLocalChecked (),
866
+ Number::New (isolate, heap_stats.total_global_handles_size ()));
867
+ stats->Set (currentContext,
868
+ String::NewFromUtf8 (isolate, " used_global_handles_size" ).ToLocalChecked (),
869
+ Number::New (isolate, heap_stats.used_global_handles_size ()));
870
+ stats->Set (currentContext,
871
+ String::NewFromUtf8 (isolate, " external_memory" ).ToLocalChecked (),
872
+ Number::New (isolate, heap_stats.external_memory ()));
873
+
874
+ args.GetReturnValue ().Set (stats);
875
+ }
876
+
815
877
void Worker::GetResourceLimits (const FunctionCallbackInfo<Value>& args) {
816
878
Worker* w;
817
879
ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
@@ -992,6 +1054,8 @@ void CreateWorkerPerIsolateProperties(IsolateData* isolate_data,
992
1054
SetProtoMethod (isolate, w, " takeHeapSnapshot" , Worker::TakeHeapSnapshot);
993
1055
SetProtoMethod (isolate, w, " loopIdleTime" , Worker::LoopIdleTime);
994
1056
SetProtoMethod (isolate, w, " loopStartTime" , Worker::LoopStartTime);
1057
+ SetProtoMethod (isolate, w, " getHeapStatistics" , Worker::GetHeapStatistics);
1058
+
995
1059
996
1060
SetConstructorFunction (isolate, target, " Worker" , w);
997
1061
}
0 commit comments