5#ifndef V8_V8_PROFILER_H_
6#define V8_V8_PROFILER_H_
11#include <unordered_set>
14#include "cppgc/common.h"
20
21
30using NativeObject =
void*;
31using SnapshotObjectId = uint32_t;
32using ProfilerId = uint32_t;
46template class V8_EXPORT std::vector<v8::CpuProfileDeoptFrame>;
60template class V8_EXPORT std::vector<v8::CpuProfileDeoptInfo>;
66
67
75
100
101
102
103
113
114
115
116
120
121
122
126
127
128
132
133
134
138
139
143
144
145
146
150
151
155
156
163
164
184
185
195
196
197
198
201
202
203
204
211
212
213
226
227
228
232
233
234
238
239
240
241
245
246
247
251
252
256
257
261
262
263
264
268
269
270
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
331
332
333
340
341
349 ProfilerId
GetId()
const {
return profiler_id_; }
354 void SetId(ProfilerId id) { profiler_id_ = id; }
356 ProfilerId profiler_id_;
360
361
368
369
370
371
372
373
374
375
376
377
378
379
380
381
384 unsigned max_samples =
kNoSampleLimit,
int sampling_interval_us = 0,
397 bool has_filter_context()
const {
return !filter_context_.IsEmpty(); }
398 void* raw_filter_context()
const;
401 unsigned max_samples_;
402 int sampling_interval_us_;
407
408
409
413
414
415
416
422
423
424
425
426
427
429 Isolate* isolate,
const std::optional<uint64_t> trace_id = std::nullopt);
432
433
437
438
439
440
444
445
446
447
448
449
453
454
455
458 std::unique_ptr<DiscardedSamplesDelegate> delegate =
nullptr);
461
462
463
464
467 std::unique_ptr<DiscardedSamplesDelegate> delegate =
nullptr);
470
471
472
473
474
475
476
477
478
479
485
486
487
488
492
493
494
495
498 std::unique_ptr<DiscardedSamplesDelegate> delegate =
nullptr);
501
502
503
504
505
506
507
508
509
510
516
517
518
519
521 bool record_samples =
false);
524
525
529
530
531
535
536
537
548
549
550
571
572
573
585
586
613
614
615
616
620
621
622
636
637
660
661
662
663
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
698
699
700
709
710
711
716
717
718
723
724
728
729
734
735
738
739
740
744
745
746
750
751
752
756
757
761
762
763
767
768
769
773
774
778
779
780
781
785
786
791
792
795
796
800
801
805
806
810
811
812
817
818
819
820
831
832
833
834
835
836
837
838
839
840
841
842
843
849
850
851
852
853
854
863 virtual const char*
Name() = 0;
866
867
868
869
875
876
880
881
882
886
887
888
889
890
894
895
896
897
898
899
907
908
909
910
911
912
913
914
915
919
920
921
922
923
924
925
926
927
928
932
933
934
938
939
940
941
942
943
944
948
949
950
951
952
953
966
967
968
973 std::vector<v8::Global<v8::Object>>* objects);
983
984
985
986
987
993
994
995
996
997
998
999
1002 uint16_t class_id,
void* data);
1011
1012
1013
1017
1018
1019
1023
1024
1025
1029
1030
1031
1032
1036
1037
1038
1039
1043
1044
1048
1049
1050
1059
1060
1063
1064
1070
1071
1072
1075
1076
1080 struct HeapSnapshotOptions
final {
1087
1088
1091
1092
1095
1096
1099
1100
1103
1104
1110
1111
1112
1113
1115 const HeapSnapshotOptions& options = HeapSnapshotOptions
());
1118
1119
1120
1121
1122
1126 bool hide_internals =
true,
bool capture_numeric_value =
false);
1129
1130
1131
1135
1136
1137
1138
1139
1140
1141
1142
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1159 int64_t* timestamp_us =
nullptr);
1162
1163
1164
1165
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1194 int stack_depth = 16,
1198
1199
1203
1204
1205
1206
1207
1211
1212
1213
1224
1225
1229
1230
1231
1232
1236
1237
1238
1239
1250
1251
1252
1261#define CODE_EVENTS_LIST(V)
1266 V(InterpretedFunction)
1276
1277
1278
1281#define V(Name) , k##Name##Type
1287
1288
1298
1299
1300
1301
1311
1312
1316
1317
1318
1319
1324
1325
1326
1327
1328
1329
1330
1334
1335
1336
1340
1341
1342
1349 void* internal_listener_;
virtual ~ActivityControl()=default
virtual ControlOption ReportProgressValue(uint32_t done, uint32_t total)=0
virtual ~AllocationProfile()=default
static const int kNoColumnNumberInfo
virtual Node * GetRootNode()=0
static const int kNoLineNumberInfo
virtual const std::vector< Sample > & GetSamples()=0
virtual void Handle(CodeEvent *code_event)=0
virtual ~CodeEventHandler()
CodeEventHandler(Isolate *isolate)
CodeEventType GetCodeType()
Local< String > GetFunctionName()
Local< String > GetScriptName()
uintptr_t GetCodeStartAddress()
const char * GetComment()
static const char * GetCodeEventTypeName(CodeEventType code_event_type)
uintptr_t GetPreviousCodeStartAddress()
int64_t GetStartTime() const
StateTag GetSampleState(int index) const
const CpuProfileNode * GetTopDownRoot() const
EmbedderStateTag GetSampleEmbedderState(int index) const
void Serialize(OutputStream *stream, SerializationFormat format=kJSON) const
int64_t GetSampleTimestamp(int index) const
Local< String > GetTitle() const
int GetSamplesCount() const
int64_t GetEndTime() const
const CpuProfileNode * GetSample(int index) const
const char * GetBailoutReason() const
const CpuProfileNode * GetParent() const
static const int kNoColumnNumberInfo
Local< String > GetFunctionName() const
static const int kNoLineNumberInfo
int GetChildrenCount() const
const std::vector< CpuProfileDeoptInfo > & GetDeoptInfos() const
unsigned GetNodeId() const
const char * GetScriptResourceNameStr() const
bool IsScriptSharedCrossOrigin() const
Local< String > GetScriptResourceName() const
bool GetLineTicks(LineTick *entries, unsigned int length) const
int GetLineNumber() const
const CpuProfileNode * GetChild(int index) const
int GetColumnNumber() const
unsigned int GetHitLineCount() const
SourceType GetSourceType() const
const char * GetFunctionNameStr() const
unsigned GetHitCount() const
static void CollectSample(Isolate *isolate, const std::optional< uint64_t > trace_id=std::nullopt)
CpuProfilingResult Start(Local< String > title, bool record_samples=false)
CpuProfile * StopProfiling(Local< String > title)
CpuProfilingResult Start(Local< String > title, CpuProfilingOptions options, std::unique_ptr< DiscardedSamplesDelegate > delegate=nullptr)
CpuProfilingResult Start(Local< String > title, CpuProfilingMode mode, bool record_samples=false, unsigned max_samples=CpuProfilingOptions::kNoSampleLimit)
CpuProfile * Stop(ProfilerId id)
void SetSamplingInterval(int us)
CpuProfilingStatus StartProfiling(Local< String > title, CpuProfilingMode mode, bool record_samples=false, unsigned max_samples=CpuProfilingOptions::kNoSampleLimit)
CpuProfilingStatus StartProfiling(Local< String > title, bool record_samples=false)
static void UseDetailedSourcePositionsForProfiling(Isolate *isolate)
void SetUsePreciseSampling(bool)
CpuProfilingStatus StartProfiling(Local< String > title, CpuProfilingOptions options, std::unique_ptr< DiscardedSamplesDelegate > delegate=nullptr)
CpuProfilingResult Start(CpuProfilingOptions options, std::unique_ptr< DiscardedSamplesDelegate > delegate=nullptr)
static CpuProfiler * New(Isolate *isolate, CpuProfilingNamingMode=kDebugNaming, CpuProfilingLoggingMode=kLazyLogging)
static const unsigned kNoSampleLimit
unsigned max_samples() const
CpuProfilingOptions & operator=(CpuProfilingOptions &&)=default
CpuProfilingMode mode() const
int sampling_interval_us() const
CpuProfilingOptions(CpuProfilingMode mode=kLeafNodeLineNumbers, unsigned max_samples=kNoSampleLimit, int sampling_interval_us=0, MaybeLocal< Context > filter_context=MaybeLocal< Context >())
CpuProfilingOptions(CpuProfilingOptions &&)=default
DiscardedSamplesDelegate()=default
virtual ~DiscardedSamplesDelegate()=default
virtual const char * NamePrefix()
virtual const char * Name()=0
virtual bool IsRootNode()
virtual Node * WrapperNode()
Node & operator=(const Node &)=delete
Node(const Node &)=delete
virtual const void * GetAddress()
virtual NativeObject GetNativeObject()
virtual Detachedness GetDetachedness()
virtual size_t SizeInBytes()=0
virtual bool IsEmbedderNode()
virtual Node * V8Node(const v8::Local< v8::Value > &value)=0
virtual ~EmbedderGraph()=default
virtual void AddEdge(Node *from, Node *to, const char *name=nullptr)=0
virtual Node * AddNode(std::unique_ptr< Node > node)=0
virtual Node * V8Node(const v8::Local< v8::Data > &value)
virtual void AddNativeSize(size_t size)
const HeapGraphNode * GetToNode() const
Local< Value > GetName() const
const HeapGraphNode * GetFromNode() const
const HeapGraphEdge * GetChild(int index) const
SnapshotObjectId GetId() const
int GetChildrenCount() const
Local< String > GetName() const
size_t GetShallowSize() const
virtual ~ObjectNameResolver()=default
virtual const char * GetName(Local< Object > object)=0
const HeapSnapshot * TakeHeapSnapshot(ActivityControl *control, ObjectNameResolver *global_object_name_resolver=nullptr, bool hide_internals=true, bool capture_numeric_value=false)
bool StartSamplingHeapProfiler(uint64_t sample_interval=512 *1024, int stack_depth=16, SamplingFlags flags=kSamplingNoFlags)
SnapshotObjectId GetObjectId(Local< Value > value)
const HeapSnapshot * TakeHeapSnapshot(const HeapSnapshotOptions &options=HeapSnapshotOptions())
void RemoveBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback, void *data)
void DeleteAllHeapSnapshots()
static const SnapshotObjectId kUnknownObjectId
const char * CopyNameForHeapSnapshot(const char *name)
AllocationProfile * GetAllocationProfile()
void StopTrackingHeapObjects()
static const uint16_t kPersistentHandleNoClassId
@ kSamplingIncludeObjectsCollectedByMinorGC
@ kSamplingIncludeObjectsCollectedByMajorGC
std::vector< v8::Local< v8::Value > > GetDetachedJSWrapperObjects()
void SetGetDetachednessCallback(GetDetachednessCallback callback, void *data)
void QueryObjects(v8::Local< v8::Context > context, QueryObjectPredicate *predicate, std::vector< v8::Global< v8::Object > > *objects)
SnapshotObjectId GetHeapStats(OutputStream *stream, int64_t *timestamp_us=nullptr)
const HeapSnapshot * GetHeapSnapshot(int index)
Local< Value > FindObjectById(SnapshotObjectId id)
void StartTrackingHeapObjects(bool track_allocations=false)
void StopSamplingHeapProfiler()
SnapshotObjectId GetObjectId(NativeObject value)
void AddBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback, void *data)
void(* BuildEmbedderGraphCallback)(v8::Isolate *isolate, v8::EmbedderGraph *graph, void *data)
const HeapGraphNode * GetNodeById(SnapshotObjectId id) const
SnapshotObjectId GetMaxSnapshotJSObjectId() const
const HeapGraphNode * GetNode(int index) const
void Serialize(OutputStream *stream, SerializationFormat format=kJSON) const
int GetNodesCount() const
const HeapGraphNode * GetRoot() const
static const int kNoColumnInfo
static const int kNoLineNumberInfo
virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate *data, int count)
virtual WriteResult WriteAsciiChunk(char *data, int size)=0
virtual int GetChunkSize()
virtual void EndOfStream()=0
virtual ~OutputStream()=default
virtual bool Filter(v8::Local< v8::Object > object)=0
virtual ~QueryObjectPredicate()=default
@ kMayContainHeapPointers
std::vector< Node * > children
Local< String > script_name
std::vector< Allocation > allocations
const char * deopt_reason
std::vector< CpuProfileDeoptFrame > stack
const CpuProfilingStatus status
ObjectNameResolver * global_object_name_resolver
HeapSnapshotMode snapshot_mode
cppgc::EmbedderStackState stack_state
NumericsMode numerics_mode
ActivityControl * control
HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
#define CODE_EVENTS_LIST(V)