@@ -338,8 +338,6 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
338
338
ExportMemory (ObjectTemplate);
339
339
340
340
ExportMisc (ObjectTemplate);
341
-
342
- ExportProfiler (ObjectTemplate);
343
341
}
344
342
345
343
~FJavascriptIsolateImplementation ()
@@ -796,173 +794,6 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
796
794
ReadOnly);
797
795
}
798
796
799
- static Local<Object> Visit (Isolate* isolate, const v8::CpuProfileNode* node)
800
- {
801
- static TMap<const v8::CpuProfileNode*, Handle<Object>> Visited;
802
-
803
- if (!isolate)
804
- {
805
- Visited.Empty ();
806
- return Local<Object>();
807
- }
808
- auto Existing = Visited.Find (node);
809
- if (Existing) return *Existing;
810
-
811
- FIsolateHelper I (isolate);
812
-
813
- auto Out = Object::New (isolate);
814
-
815
- Visited.Add (node, Out);
816
-
817
- Out->Set (I.Keyword (" ScriptResourceName" ), node->GetScriptResourceName ());
818
- Out->Set (I.Keyword (" FunctionName" ), node->GetFunctionName ());
819
- Out->Set (I.Keyword (" HitCount" ), Integer::NewFromUnsigned (isolate,node->GetHitCount ()));
820
- Out->Set (I.Keyword (" LineNumber" ), Integer::New (isolate,node->GetLineNumber ()));
821
- Out->Set (I.Keyword (" ColumnNumber" ), Integer::New (isolate,node->GetColumnNumber ()));
822
- Out->Set (I.Keyword (" ScriptId" ), Integer::New (isolate, node->GetScriptId ()));
823
-
824
- {
825
- uint32_t Num = node->GetHitLineCount ();
826
- TArray<v8::CpuProfileNode::LineTick> Buffer;
827
- Buffer.AddDefaulted (Num);
828
- node->GetLineTicks (Buffer.GetData (), Num);
829
-
830
- auto Arr = Array::New (isolate, Num);
831
- for (uint32_t Index = 0 ; Index < Num; ++Index)
832
- {
833
- const auto & info = Buffer[Index];
834
- auto item = Object::New (isolate);
835
- item->Set (I.Keyword (" line" ), Integer::New (isolate,info.line ));
836
- item->Set (I.Keyword (" hit_count" ), Integer::New (isolate, info.hit_count ));
837
- Arr->Set (Index, item);
838
- }
839
- Out->Set (I.Keyword (" LineTicks" ), Arr);
840
- }
841
-
842
- auto BailOutReason = node->GetBailoutReason ();
843
- if (BailOutReason)
844
- {
845
- Out->Set (I.Keyword (" BailOutReason" ), I.Keyword (BailOutReason));
846
- }
847
-
848
- {
849
- const auto & deopt = node->GetDeoptInfos ();
850
- uint32_t Num = deopt.size ();
851
- if (Num)
852
- {
853
- auto Arr = Array::New (isolate, deopt.size ());
854
- for (uint32_t Index = 0 ; Index < Num; ++Index)
855
- {
856
- const auto & info = deopt[Index];
857
- FString out;
858
- for (const auto & frame : info.stack )
859
- {
860
- out.Append (FString::Printf (TEXT (" %d:%d " ), (int )frame.script_id , (int )frame.position ));
861
- }
862
- auto item = Object::New (isolate);
863
- item->Set (I.Keyword (" reason" ), I.Keyword (deopt[Index].deopt_reason ));
864
- item->Set (I.Keyword (" stack" ), I.String (out));
865
- Arr->Set (Index, item);
866
- }
867
- Out->Set (I.Keyword (" DeoptInfos" ), Arr);
868
- }
869
- }
870
-
871
- uint32_t Num = node->GetChildrenCount ();
872
- if (Num)
873
- {
874
- auto Arr = Array::New (isolate, Num);
875
- for (uint32_t Index = 0 ; Index < Num; ++Index)
876
- {
877
- Arr->Set (Index, Visit (isolate, node->GetChild (Index)));
878
- }
879
- Out->Set (I.Keyword (" Children" ), Arr);
880
- }
881
- return Out;
882
- };
883
-
884
- void ExportProfiler (Local<ObjectTemplate> global_templ)
885
- {
886
- FIsolateHelper I (isolate_);
887
-
888
- Local<FunctionTemplate> Template = I.FunctionTemplate ();
889
-
890
- auto add_fn = [&](const char * name, FunctionCallback fn) {
891
- Template->PrototypeTemplate ()->Set (I.Keyword (name), I.FunctionTemplate (fn));
892
- };
893
-
894
- add_fn (" SetSamplingInterval" , [](const FunctionCallbackInfo<Value>& info)
895
- {
896
- FIsolateHelper I (info.GetIsolate ());
897
-
898
- auto profiler = info.GetIsolate ()->GetCpuProfiler ();
899
-
900
- if (info.Length () == 1 )
901
- {
902
- profiler->SetSamplingInterval (info[0 ]->IntegerValue ());
903
- }
904
- });
905
-
906
- add_fn (" StartProfiling" , [](const FunctionCallbackInfo<Value>& info)
907
- {
908
- FIsolateHelper I (info.GetIsolate ());
909
-
910
- auto profiler = info.GetIsolate ()->GetCpuProfiler ();
911
-
912
- if (info.Length () == 2 )
913
- {
914
- profiler->StartProfiling (info[0 ].As <String>(), info[1 ]->BooleanValue ());
915
- info.GetReturnValue ().Set (true );
916
- }
917
- });
918
-
919
- add_fn (" StopProfiling" , [](const FunctionCallbackInfo<Value>& info)
920
- {
921
- auto isolate = info.GetIsolate ();
922
- FIsolateHelper I (isolate);
923
-
924
- auto profiler = isolate->GetCpuProfiler ();
925
-
926
- if (info.Length () == 1 )
927
- {
928
- auto Profile = profiler->StopProfiling (info[0 ].As <String>());
929
- if (!Profile) return ;
930
-
931
- auto Out = Object::New (isolate);
932
- Out->Set (I.Keyword (" Root" ), Visit (isolate, Profile->GetTopDownRoot ()));
933
- Out->Set (I.Keyword (" Title" ), Profile->GetTitle ());
934
-
935
- {
936
- uint32_t Num = Profile->GetSamplesCount ();
937
- if (Num)
938
- {
939
- auto Arr = Array::New (isolate, Num);
940
- for (uint32_t Index = 0 ; Index < Num; ++Index)
941
- {
942
- Arr->Set (Index, Visit (isolate, Profile->GetSample (Index)));
943
- }
944
- Out->Set (I.Keyword (" Samples" ), Arr);
945
- }
946
- }
947
-
948
-
949
- // cleanup
950
- Visit (nullptr , nullptr );
951
-
952
- info.GetReturnValue ().Set (Out);
953
-
954
- Profile->Delete ();
955
- }
956
- });
957
-
958
- global_templ->Set (
959
- I.Keyword (" v8" ),
960
- // Create an instance
961
- Template->GetFunction ()->NewInstance (),
962
- // Do not modify!
963
- ReadOnly);
964
- }
965
-
966
797
void ExportMisc (Local<ObjectTemplate> global_templ)
967
798
{
968
799
FIsolateHelper I (isolate_);
0 commit comments