@@ -54,7 +54,7 @@ namespace v8 {
5454 */
5555class V8_EXPORT TracingCpuProfiler {
5656 public:
57- V8_DEPRECATE_SOON (
57+ V8_DEPRECATED (
5858 " The profiler is created automatically with the isolate.\n "
5959 " No need to create it explicitly." ,
6060 static std::unique_ptr<TracingCpuProfiler> Create (Isolate*));
@@ -278,6 +278,16 @@ class V8_EXPORT CpuProfile {
278278 void Delete ();
279279};
280280
281+ enum CpuProfilingMode {
282+ // In the resulting CpuProfile tree, intermediate nodes in a stack trace
283+ // (from the root to a leaf) will have line numbers that point to the start
284+ // line of the function, rather than the line of the callsite of the child.
285+ kLeafNodeLineNumbers ,
286+ // In the resulting CpuProfile tree, nodes are separated based on the line
287+ // number of their callsite in their parent.
288+ kCallerLineNumbers ,
289+ };
290+
281291/* *
282292 * Interface for controlling CPU profiling. Instance of the
283293 * profiler can be created using v8::CpuProfiler::New method.
@@ -321,6 +331,13 @@ class V8_EXPORT CpuProfiler {
321331 * |record_samples| parameter controls whether individual samples should
322332 * be recorded in addition to the aggregated tree.
323333 */
334+ void StartProfiling (Local<String> title, CpuProfilingMode mode,
335+ bool record_samples = false );
336+ /* *
337+ * The same as StartProfiling above, but the CpuProfilingMode defaults to
338+ * kLeafNodeLineNumbers mode, which was the previous default behavior of the
339+ * profiler.
340+ */
324341 void StartProfiling (Local<String> title, bool record_samples = false );
325342
326343 /* *
@@ -643,7 +660,7 @@ class V8_EXPORT AllocationProfile {
643660 * Usage:
644661 * 1) Define derived class of EmbedderGraph::Node for embedder objects.
645662 * 2) Set the build embedder graph callback on the heap profiler using
646- * HeapProfiler::SetBuildEmbedderGraphCallback .
663+ * HeapProfiler::AddBuildEmbedderGraphCallback .
647664 * 3) In the callback use graph->AddEdge(node1, node2) to add an edge from
648665 * node1 to node2.
649666 * 4) To represent references from/to V8 object, construct V8 nodes using
@@ -697,11 +714,14 @@ class V8_EXPORT EmbedderGraph {
697714 virtual Node* AddNode (std::unique_ptr<Node> node) = 0;
698715
699716 /* *
700- * Adds an edge that represents a strong reference from the given node
701- * |from| to the given node |to|. The nodes must be added to the graph
717+ * Adds an edge that represents a strong reference from the given
718+ * node |from| to the given node |to|. The nodes must be added to the graph
702719 * before calling this function.
720+ *
721+ * If name is nullptr, the edge will have auto-increment indexes, otherwise
722+ * it will be named accordingly.
703723 */
704- virtual void AddEdge (Node* from, Node* to) = 0;
724+ virtual void AddEdge (Node* from, Node* to, const char * name = nullptr ) = 0;
705725
706726 virtual ~EmbedderGraph () = default ;
707727};
@@ -751,6 +771,11 @@ class V8_EXPORT HeapProfiler {
751771 * The callback must not trigger garbage collection in V8.
752772 */
753773 typedef void (*BuildEmbedderGraphCallback)(v8::Isolate* isolate,
774+ v8::EmbedderGraph* graph,
775+ void * data);
776+
777+ /* * TODO(addaleax): Remove */
778+ typedef void (*LegacyBuildEmbedderGraphCallback)(v8::Isolate* isolate,
754779 v8::EmbedderGraph* graph);
755780
756781 /* * Returns the number of snapshots taken. */
@@ -893,15 +918,22 @@ class V8_EXPORT HeapProfiler {
893918
894919 /* * Binds a callback to embedder's class ID. */
895920 V8_DEPRECATED (
896- " Use SetBuildEmbedderGraphCallback to provide info about embedder nodes" ,
921+ " Use AddBuildEmbedderGraphCallback to provide info about embedder nodes" ,
897922 void SetWrapperClassInfoProvider (uint16_t class_id,
898923 WrapperInfoCallback callback));
899924
900925 V8_DEPRECATED (
901- " Use SetBuildEmbedderGraphCallback to provide info about embedder nodes" ,
926+ " Use AddBuildEmbedderGraphCallback to provide info about embedder nodes" ,
902927 void SetGetRetainerInfosCallback (GetRetainerInfosCallback callback));
903928
904- void SetBuildEmbedderGraphCallback (BuildEmbedderGraphCallback callback);
929+ V8_DEPRECATE_SOON (
930+ " Use AddBuildEmbedderGraphCallback to provide info about embedder nodes" ,
931+ void SetBuildEmbedderGraphCallback (
932+ LegacyBuildEmbedderGraphCallback callback));
933+ void AddBuildEmbedderGraphCallback (BuildEmbedderGraphCallback callback,
934+ void * data);
935+ void RemoveBuildEmbedderGraphCallback (BuildEmbedderGraphCallback callback,
936+ void * data);
905937
906938 /* *
907939 * Default value of persistent handle class ID. Must not be used to
@@ -1009,6 +1041,76 @@ struct HeapStatsUpdate {
10091041 uint32_t size; // New value of size field for the interval with this index.
10101042};
10111043
1044+ #define CODE_EVENTS_LIST (V ) \
1045+ V (Builtin) \
1046+ V(Callback) \
1047+ V(Eval) \
1048+ V(Function) \
1049+ V(InterpretedFunction) \
1050+ V(Handler) \
1051+ V(BytecodeHandler) \
1052+ V(LazyCompile) \
1053+ V(RegExp) \
1054+ V(Script) \
1055+ V(Stub)
1056+
1057+ /* *
1058+ * Note that this enum may be extended in the future. Please include a default
1059+ * case if this enum is used in a switch statement.
1060+ */
1061+ enum CodeEventType {
1062+ kUnknownType = 0
1063+ #define V (Name ) , k##Name##Type
1064+ CODE_EVENTS_LIST (V)
1065+ #undef V
1066+ };
1067+
1068+ /* *
1069+ * Representation of a code creation event
1070+ */
1071+ class V8_EXPORT CodeEvent {
1072+ public:
1073+ uintptr_t GetCodeStartAddress ();
1074+ size_t GetCodeSize ();
1075+ Local<String> GetFunctionName ();
1076+ Local<String> GetScriptName ();
1077+ int GetScriptLine ();
1078+ int GetScriptColumn ();
1079+ /* *
1080+ * NOTE (mmarchini): We can't allocate objects in the heap when we collect
1081+ * existing code, and both the code type and the comment are not stored in the
1082+ * heap, so we return those as const char*.
1083+ */
1084+ CodeEventType GetCodeType ();
1085+ const char * GetComment ();
1086+
1087+ static const char * GetCodeEventTypeName (CodeEventType code_event_type);
1088+ };
1089+
1090+ /* *
1091+ * Interface to listen to code creation events.
1092+ */
1093+ class V8_EXPORT CodeEventHandler {
1094+ public:
1095+ /* *
1096+ * Creates a new listener for the |isolate|. The isolate must be initialized.
1097+ * The listener object must be disposed after use by calling |Dispose| method.
1098+ * Multiple listeners can be created for the same isolate.
1099+ */
1100+ explicit CodeEventHandler (Isolate* isolate);
1101+ virtual ~CodeEventHandler ();
1102+
1103+ virtual void Handle (CodeEvent* code_event) = 0;
1104+
1105+ void Enable ();
1106+ void Disable ();
1107+
1108+ private:
1109+ CodeEventHandler ();
1110+ CodeEventHandler (const CodeEventHandler&);
1111+ CodeEventHandler& operator =(const CodeEventHandler&);
1112+ void * internal_listener_;
1113+ };
10121114
10131115} // namespace v8
10141116
0 commit comments