Loading...
Searching...
No Matches
v8-profiler.h
Go to the documentation of this file.
1// Copyright 2010 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_V8_PROFILER_H_
6#define V8_V8_PROFILER_H_
7
8#include <unordered_set>
9#include <vector>
10#include "v8.h" // NOLINT(build/include)
11
15namespace v8 {
16
17class HeapGraphNode;
18struct HeapStatsUpdate;
19
20typedef uint32_t SnapshotObjectId;
21
22
25 size_t position;
26};
27
28} // namespace v8
29
30#ifdef V8_OS_WIN
31template class V8_EXPORT std::vector<v8::CpuProfileDeoptFrame>;
32#endif
33
34namespace v8 {
35
38 const char* deopt_reason;
39 std::vector<CpuProfileDeoptFrame> stack;
40};
41
42} // namespace v8
43
44#ifdef V8_OS_WIN
45template class V8_EXPORT std::vector<v8::CpuProfileDeoptInfo>;
46#endif
47
48namespace v8 {
49
56 public:
57 static std::unique_ptr<TracingCpuProfiler> Create(Isolate*);
58 virtual ~TracingCpuProfiler() = default;
59
60 protected:
61 TracingCpuProfiler() = default;
62};
63
64// TickSample captures the information collected for each sample.
65struct TickSample {
66 // Internal profiling (with --prof + tools/$OS-tick-processor) wants to
67 // include the runtime function we're calling. Externally exposed tick
68 // samples don't care.
69 enum RecordCEntryFrame { kIncludeCEntryFrame, kSkipCEntryFrame };
70
72 : state(OTHER),
73 pc(nullptr),
74 external_callback_entry(nullptr),
75 frames_count(0),
76 has_external_callback(false),
77 update_stats(true) {}
78
91 void Init(Isolate* isolate, const v8::RegisterState& state,
92 RecordCEntryFrame record_c_entry_frame, bool update_stats,
93 bool use_simulator_reg_state = true);
114 static bool GetStackSample(Isolate* isolate, v8::RegisterState* state,
115 RecordCEntryFrame record_c_entry_frame,
116 void** frames, size_t frames_limit,
117 v8::SampleInfo* sample_info,
118 bool use_simulator_reg_state = true);
119 StateTag state; // The state of the VM.
120 void* pc; // Instruction pointer.
121 union {
122 void* tos; // Top stack value (*sp).
124 };
125 static const unsigned kMaxFramesCountLog2 = 8;
126 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1;
127 void* stack[kMaxFramesCount]; // Call stack.
128 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames.
130 bool update_stats : 1; // Whether the sample should update aggregated stats.
131};
132
137 public:
138 struct LineTick {
140 int line;
141
143 unsigned int hit_count;
144 };
145
148
154 const char* GetFunctionNameStr() const;
155
157 int GetScriptId() const;
158
161
167 const char* GetScriptResourceNameStr() const;
168
173 int GetLineNumber() const;
174
179 int GetColumnNumber() const;
180
184 unsigned int GetHitLineCount() const;
185
191 bool GetLineTicks(LineTick* entries, unsigned int length) const;
192
196 const char* GetBailoutReason() const;
197
201 unsigned GetHitCount() const;
202
205 "Use GetScriptId, GetLineNumber, and GetColumnNumber instead.",
206 unsigned GetCallUid() const);
207
209 unsigned GetNodeId() const;
210
212 int GetChildrenCount() const;
213
215 const CpuProfileNode* GetChild(int index) const;
216
218 const std::vector<CpuProfileDeoptInfo>& GetDeoptInfos() const;
219
220 static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
221 static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
222};
223
224
230 public:
233
236
241 int GetSamplesCount() const;
242
247 const CpuProfileNode* GetSample(int index) const;
248
254 int64_t GetSampleTimestamp(int index) const;
255
260 int64_t GetStartTime() const;
261
267 int64_t GetEndTime() const;
268
273 void Delete();
274};
275
281 public:
287 static CpuProfiler* New(Isolate* isolate);
288
292 void Dispose();
293
300
312 void StartProfiling(Local<String> title, bool record_samples = false);
313
319
326
330 void SetIdle(bool is_idle);
331
332 private:
333 CpuProfiler();
334 ~CpuProfiler();
335 CpuProfiler(const CpuProfiler&);
336 CpuProfiler& operator=(const CpuProfiler&);
337};
338
339
345 public:
346 enum Type {
347 kContextVariable = 0, // A variable from a function context.
348 kElement = 1, // An element of an array.
349 kProperty = 2, // A named object property.
350 kInternal = 3, // A link that can't be accessed from JS,
351 // thus, its name isn't a real property name
352 // (e.g. parts of a ConsString).
353 kHidden = 4, // A link that is needed for proper sizes
354 // calculation, but may be hidden from user.
355 kShortcut = 5, // A link that must not be followed during
356 // sizes calculation.
357 kWeak = 6 // A weak reference (ignored by the GC).
358 };
359
361 Type GetType() const;
362
368
371
373 const HeapGraphNode* GetToNode() const;
374};
375
376
381 public:
382 enum Type {
383 kHidden = 0, // Hidden node, may be filtered when shown to user.
384 kArray = 1, // An array of elements.
385 kString = 2, // A string.
386 kObject = 3, // A JS object (except for arrays and strings).
387 kCode = 4, // Compiled code.
388 kClosure = 5, // Function closure.
389 kRegExp = 6, // RegExp.
390 kHeapNumber = 7, // Number stored in the heap.
391 kNative = 8, // Native object (not from V8 heap).
392 kSynthetic = 9, // Synthetic object, usually used for grouping
393 // snapshot items together.
394 kConsString = 10, // Concatenated string. A pair of pointers to strings.
395 kSlicedString = 11, // Sliced string. A fragment of another string.
396 kSymbol = 12 // A Symbol (ES6).
397 };
398
400 Type GetType() const;
401
408
414
416 size_t GetShallowSize() const;
417
419 int GetChildrenCount() const;
420
422 const HeapGraphEdge* GetChild(int index) const;
423};
424
425
429class V8_EXPORT OutputStream { // NOLINT
430 public:
432 kContinue = 0,
433 kAbort = 1
434 };
435 virtual ~OutputStream() {}
437 virtual void EndOfStream() = 0;
439 virtual int GetChunkSize() { return 1024; }
445 virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
452 return kAbort;
453 }
454};
455
456
461 public:
463 kJSON = 0 // See format description near 'Serialize' method.
464 };
465
467 const HeapGraphNode* GetRoot() const;
468
471
473 int GetNodesCount() const;
474
476 const HeapGraphNode* GetNode(int index) const;
477
480
486 void Delete();
487
515 SerializationFormat format = kJSON) const;
516};
517
518
523class V8_EXPORT ActivityControl { // NOLINT
524 public:
526 kContinue = 0,
527 kAbort = 1
528 };
529 virtual ~ActivityControl() {}
534 virtual ControlOption ReportProgressValue(int done, int total) = 0;
535};
536
537
543 public:
544 struct Allocation {
548 size_t size;
549
553 unsigned int count;
554 };
555
559 struct Node {
565
571
577
582
588
594
600 std::vector<Node*> children;
601
605 std::vector<Allocation> allocations;
606 };
607
613 virtual Node* GetRootNode() = 0;
614
616
617 static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
618 static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
619};
620
621
627 public:
629 kSamplingNoFlags = 0,
630 kSamplingForceGC = 1 << 0,
631 };
632
633 typedef std::unordered_set<const v8::PersistentBase<v8::Value>*>
635 typedef std::vector<std::pair<v8::RetainedObjectInfo*, RetainerChildren>>
637 typedef std::vector<std::pair<const v8::PersistentBase<v8::Value>*,
640
644 };
645
649 typedef RetainerInfos (*GetRetainerInfosCallback)(v8::Isolate* isolate);
650
657 typedef RetainedObjectInfo* (*WrapperInfoCallback)(uint16_t class_id,
658 Local<Value> wrapper);
659
662
664 const HeapSnapshot* GetHeapSnapshot(int index);
665
671
677
684
690 static const SnapshotObjectId kUnknownObjectId = 0;
691
696 public:
701 virtual const char* GetName(Local<Object> object) = 0;
702
703 protected:
705 };
706
711 ActivityControl* control = NULL,
712 ObjectNameResolver* global_object_name_resolver = NULL);
713
723 void StartTrackingHeapObjects(bool track_allocations = false);
724
739 int64_t* timestamp_us = NULL);
740
747
775 bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024,
776 int stack_depth = 16,
777 SamplingFlags flags = kSamplingNoFlags);
778
783
791
797
800 uint16_t class_id,
801 WrapperInfoCallback callback);
802
803 void SetGetRetainerInfosCallback(GetRetainerInfosCallback callback);
804
810 static const uint16_t kPersistentHandleNoClassId = 0;
811
812 private:
813 HeapProfiler();
816 HeapProfiler& operator=(const HeapProfiler&);
817};
818
844 public:
846 virtual void Dispose() = 0;
847
849 virtual bool IsEquivalent(RetainedObjectInfo* other) = 0;
850
855 virtual intptr_t GetHash() = 0;
856
861 virtual const char* GetLabel() = 0;
862
872 virtual const char* GetGroupLabel() { return GetLabel(); }
873
878 virtual intptr_t GetElementCount() { return -1; }
879
881 virtual intptr_t GetSizeInBytes() { return -1; }
882
883 protected:
886
887 private:
889 RetainedObjectInfo& operator=(const RetainedObjectInfo&);
890};
891
892
898 HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
899 : index(index), count(count), size(size) { }
900 uint32_t index; // Index of the time interval that was changed.
901 uint32_t count; // New value of count field for the interval with this index.
902 uint32_t size; // New value of size field for the interval with this index.
903};
904
905
906} // namespace v8
907
908
909#endif // V8_V8_PROFILER_H_
Definition: v8-profiler.h:523
virtual ControlOption ReportProgressValue(int done, int total)=0
ControlOption
Definition: v8-profiler.h:525
virtual ~ActivityControl()
Definition: v8-profiler.h:529
Definition: v8-profiler.h:542
virtual ~AllocationProfile()
Definition: v8-profiler.h:615
virtual Node * GetRootNode()=0
Definition: v8-profiler.h:136
const CpuProfileNode * GetChild(int index) const
bool GetLineTicks(LineTick *entries, unsigned int length) const
unsigned GetHitCount() const
unsigned int GetHitLineCount() const
int GetLineNumber() const
unsigned GetNodeId() const
const char * GetScriptResourceNameStr() const
unsigned GetCallUid() const
const char * GetFunctionNameStr() const
const std::vector< CpuProfileDeoptInfo > & GetDeoptInfos() const
int GetColumnNumber() const
Local< String > GetFunctionName() const
Local< String > GetScriptResourceName() const
const char * GetBailoutReason() const
int GetScriptId() const
int GetChildrenCount() const
Definition: v8-profiler.h:229
const CpuProfileNode * GetTopDownRoot() const
int GetSamplesCount() const
Local< String > GetTitle() const
int64_t GetEndTime() const
const CpuProfileNode * GetSample(int index) const
int64_t GetSampleTimestamp(int index) const
int64_t GetStartTime() const
Definition: v8-profiler.h:280
void SetIdle(bool is_idle)
void StartProfiling(Local< String > title, bool record_samples=false)
CpuProfile * StopProfiling(Local< String > title)
void CollectSample()
void SetSamplingInterval(int us)
static CpuProfiler * New(Isolate *isolate)
Definition: v8-profiler.h:344
Type
Definition: v8-profiler.h:346
const HeapGraphNode * GetToNode() const
const HeapGraphNode * GetFromNode() const
Type GetType() const
Local< Value > GetName() const
Definition: v8-profiler.h:380
Local< String > GetName() const
SnapshotObjectId GetId() const
Type GetType() const
Type
Definition: v8-profiler.h:382
const HeapGraphEdge * GetChild(int index) const
size_t GetShallowSize() const
int GetChildrenCount() const
Definition: v8-profiler.h:695
virtual ~ObjectNameResolver()
Definition: v8-profiler.h:704
virtual const char * GetName(Local< Object > object)=0
Definition: v8-profiler.h:626
void StartTrackingHeapObjects(bool track_allocations=false)
Local< Value > FindObjectById(SnapshotObjectId id)
AllocationProfile * GetAllocationProfile()
std::unordered_set< const v8::PersistentBase< v8::Value > * > RetainerChildren
Definition: v8-profiler.h:634
void DeleteAllHeapSnapshots()
bool StartSamplingHeapProfiler(uint64_t sample_interval=512 *1024, int stack_depth=16, SamplingFlags flags=kSamplingNoFlags)
SnapshotObjectId GetHeapStats(OutputStream *stream, int64_t *timestamp_us=NULL)
void SetWrapperClassInfoProvider(uint16_t class_id, WrapperInfoCallback callback)
void SetGetRetainerInfosCallback(GetRetainerInfosCallback callback)
const HeapSnapshot * TakeHeapSnapshot(ActivityControl *control=NULL, ObjectNameResolver *global_object_name_resolver=NULL)
SamplingFlags
Definition: v8-profiler.h:628
std::vector< std::pair< const v8::PersistentBase< v8::Value > *, const v8::PersistentBase< v8::Value > * > > RetainerEdges
Definition: v8-profiler.h:639
std::vector< std::pair< v8::RetainedObjectInfo *, RetainerChildren > > RetainerGroups
Definition: v8-profiler.h:636
SnapshotObjectId GetObjectId(Local< Value > value)
void StopSamplingHeapProfiler()
const HeapSnapshot * GetHeapSnapshot(int index)
void StopTrackingHeapObjects()
Definition: v8-profiler.h:460
const HeapGraphNode * GetNodeById(SnapshotObjectId id) const
int GetNodesCount() const
SerializationFormat
Definition: v8-profiler.h:462
const HeapGraphNode * GetRoot() const
SnapshotObjectId GetMaxSnapshotJSObjectId() const
const HeapGraphNode * GetNode(int index) const
void Serialize(OutputStream *stream, SerializationFormat format=kJSON) const
Definition: v8.h:6768
Definition: v8.h:197
Definition: v8-profiler.h:429
virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate *data, int count)
Definition: v8-profiler.h:451
WriteResult
Definition: v8-profiler.h:431
virtual ~OutputStream()
Definition: v8-profiler.h:435
virtual WriteResult WriteAsciiChunk(char *data, int size)=0
virtual void EndOfStream()=0
virtual int GetChunkSize()
Definition: v8-profiler.h:439
Definition: v8.h:481
Definition: v8-profiler.h:843
virtual const char * GetGroupLabel()
Definition: v8-profiler.h:872
virtual intptr_t GetSizeInBytes()
Definition: v8-profiler.h:881
RetainedObjectInfo()
Definition: v8-profiler.h:884
virtual bool IsEquivalent(RetainedObjectInfo *other)=0
virtual ~RetainedObjectInfo()
Definition: v8-profiler.h:885
virtual void Dispose()=0
virtual intptr_t GetHash()=0
virtual const char * GetLabel()=0
virtual intptr_t GetElementCount()
Definition: v8-profiler.h:878
Definition: v8-profiler.h:55
TracingCpuProfiler()=default
virtual ~TracingCpuProfiler()=default
static std::unique_ptr< TracingCpuProfiler > Create(Isolate *)
Definition: libplatform.h:12
uint32_t SnapshotObjectId
Definition: v8-profiler.h:20
@ kWeak
Definition: v8-util.h:29
StateTag
Definition: v8.h:1729
@ OTHER
Definition: v8.h:1735
Definition: v8-profiler.h:544
unsigned int count
Definition: v8-profiler.h:553
size_t size
Definition: v8-profiler.h:548
Definition: v8-profiler.h:559
std::vector< Node * > children
Definition: v8-profiler.h:600
int script_id
Definition: v8-profiler.h:576
int start_position
Definition: v8-profiler.h:581
std::vector< Allocation > allocations
Definition: v8-profiler.h:605
int column_number
Definition: v8-profiler.h:593
int line_number
Definition: v8-profiler.h:587
Local< String > script_name
Definition: v8-profiler.h:570
Local< String > name
Definition: v8-profiler.h:564
Definition: v8-profiler.h:23
size_t position
Definition: v8-profiler.h:25
int script_id
Definition: v8-profiler.h:24
Definition: v8-profiler.h:36
const char * deopt_reason
Definition: v8-profiler.h:38
std::vector< CpuProfileDeoptFrame > stack
Definition: v8-profiler.h:39
Definition: v8-profiler.h:138
unsigned int hit_count
Definition: v8-profiler.h:143
int line
Definition: v8-profiler.h:140
Definition: v8-profiler.h:641
RetainerEdges edges
Definition: v8-profiler.h:643
RetainerGroups groups
Definition: v8-profiler.h:642
Definition: v8-profiler.h:897
uint32_t size
Definition: v8-profiler.h:902
uint32_t index
Definition: v8-profiler.h:900
uint32_t count
Definition: v8-profiler.h:901
HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
Definition: v8-profiler.h:898
Definition: v8.h:1742
Definition: v8.h:1750
Definition: v8-profiler.h:65
unsigned frames_count
Definition: v8-profiler.h:128
TickSample()
Definition: v8-profiler.h:71
void * external_callback_entry
Definition: v8-profiler.h:123
static bool GetStackSample(Isolate *isolate, v8::RegisterState *state, RecordCEntryFrame record_c_entry_frame, void **frames, size_t frames_limit, v8::SampleInfo *sample_info, bool use_simulator_reg_state=true)
void * pc
Definition: v8-profiler.h:120
void Init(Isolate *isolate, const v8::RegisterState &state, RecordCEntryFrame record_c_entry_frame, bool update_stats, bool use_simulator_reg_state=true)
StateTag state
Definition: v8-profiler.h:119
void * tos
Definition: v8-profiler.h:122
bool has_external_callback
Definition: v8-profiler.h:129
RecordCEntryFrame
Definition: v8-profiler.h:69
@ kIncludeCEntryFrame
Definition: v8-profiler.h:69
bool update_stats
Definition: v8-profiler.h:130
#define V8_EXPORT
Definition: v8.h:56
#define V8_DEPRECATE_SOON(message, declarator)
Definition: v8config.h:340