v8  5.1.281(node6.17.1)
V8 is Google's open source JavaScript engine
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 <vector>
9 #include "v8.h" // NOLINT(build/include)
10 
14 namespace v8 {
15 
16 class HeapGraphNode;
18 
19 typedef uint32_t SnapshotObjectId;
20 
21 
23  int script_id;
24  size_t position;
25 };
26 
27 } // namespace v8
28 
29 #ifdef V8_OS_WIN
30 template class V8_EXPORT std::vector<v8::CpuProfileDeoptFrame>;
31 #endif
32 
33 namespace v8 {
34 
37  const char* deopt_reason;
38  std::vector<CpuProfileDeoptFrame> stack;
39 };
40 
41 } // namespace v8
42 
43 #ifdef V8_OS_WIN
44 template class V8_EXPORT std::vector<v8::CpuProfileDeoptInfo>;
45 #endif
46 
47 namespace v8 {
48 
53  public:
54  struct LineTick {
56  int line;
57 
59  unsigned int hit_count;
60  };
61 
63  Local<String> GetFunctionName() const;
64 
66  int GetScriptId() const;
67 
69  Local<String> GetScriptResourceName() const;
70 
75  int GetLineNumber() const;
76 
81  int GetColumnNumber() const;
82 
86  unsigned int GetHitLineCount() const;
87 
93  bool GetLineTicks(LineTick* entries, unsigned int length) const;
94 
98  const char* GetBailoutReason() const;
99 
103  unsigned GetHitCount() const;
104 
106  unsigned GetCallUid() const;
107 
109  unsigned GetNodeId() const;
110 
112  int GetChildrenCount() const;
113 
115  const CpuProfileNode* GetChild(int index) const;
116 
118  const std::vector<CpuProfileDeoptInfo>& GetDeoptInfos() const;
119 
120  static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
121  static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
122 };
123 
124 
130  public:
132  Local<String> GetTitle() const;
133 
135  const CpuProfileNode* GetTopDownRoot() const;
136 
141  int GetSamplesCount() const;
142 
147  const CpuProfileNode* GetSample(int index) const;
148 
154  int64_t GetSampleTimestamp(int index) const;
155 
160  int64_t GetStartTime() const;
161 
167  int64_t GetEndTime() const;
168 
173  void Delete();
174 };
175 
176 
182  public:
188  void SetSamplingInterval(int us);
189 
201  void StartProfiling(Local<String> title, bool record_samples = false);
202 
207  CpuProfile* StopProfiling(Local<String> title);
208 
214  void CollectSample();
215 
219  void SetIdle(bool is_idle);
220 
221  private:
222  CpuProfiler();
223  ~CpuProfiler();
224  CpuProfiler(const CpuProfiler&);
225  CpuProfiler& operator=(const CpuProfiler&);
226 };
227 
228 
234  public:
235  enum Type {
236  kContextVariable = 0, // A variable from a function context.
237  kElement = 1, // An element of an array.
238  kProperty = 2, // A named object property.
239  kInternal = 3, // A link that can't be accessed from JS,
240  // thus, its name isn't a real property name
241  // (e.g. parts of a ConsString).
242  kHidden = 4, // A link that is needed for proper sizes
243  // calculation, but may be hidden from user.
244  kShortcut = 5, // A link that must not be followed during
245  // sizes calculation.
246  kWeak = 6 // A weak reference (ignored by the GC).
247  };
248 
250  Type GetType() const;
251 
256  Local<Value> GetName() const;
257 
259  const HeapGraphNode* GetFromNode() const;
260 
262  const HeapGraphNode* GetToNode() const;
263 };
264 
265 
270  public:
271  enum Type {
272  kHidden = 0, // Hidden node, may be filtered when shown to user.
273  kArray = 1, // An array of elements.
274  kString = 2, // A string.
275  kObject = 3, // A JS object (except for arrays and strings).
276  kCode = 4, // Compiled code.
277  kClosure = 5, // Function closure.
278  kRegExp = 6, // RegExp.
279  kHeapNumber = 7, // Number stored in the heap.
280  kNative = 8, // Native object (not from V8 heap).
281  kSynthetic = 9, // Synthetic object, usualy used for grouping
282  // snapshot items together.
283  kConsString = 10, // Concatenated string. A pair of pointers to strings.
284  kSlicedString = 11, // Sliced string. A fragment of another string.
285  kSymbol = 12, // A Symbol (ES6).
286  kSimdValue = 13 // A SIMD value stored in the heap (Proposed ES7).
287  };
288 
290  Type GetType() const;
291 
297  Local<String> GetName() const;
298 
303  SnapshotObjectId GetId() const;
304 
306  size_t GetShallowSize() const;
307 
309  int GetChildrenCount() const;
310 
312  const HeapGraphEdge* GetChild(int index) const;
313 };
314 
315 
319 class V8_EXPORT OutputStream { // NOLINT
320  public:
321  enum WriteResult {
322  kContinue = 0,
323  kAbort = 1
324  };
325  virtual ~OutputStream() {}
327  virtual void EndOfStream() = 0;
329  virtual int GetChunkSize() { return 1024; }
335  virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
341  virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
342  return kAbort;
343  }
344 };
345 
346 
351  public:
353  kJSON = 0 // See format description near 'Serialize' method.
354  };
355 
357  const HeapGraphNode* GetRoot() const;
358 
360  const HeapGraphNode* GetNodeById(SnapshotObjectId id) const;
361 
363  int GetNodesCount() const;
364 
366  const HeapGraphNode* GetNode(int index) const;
367 
369  SnapshotObjectId GetMaxSnapshotJSObjectId() const;
370 
376  void Delete();
377 
404  void Serialize(OutputStream* stream,
405  SerializationFormat format = kJSON) const;
406 };
407 
408 
413 class V8_EXPORT ActivityControl { // NOLINT
414  public:
416  kContinue = 0,
417  kAbort = 1
418  };
419  virtual ~ActivityControl() {}
424  virtual ControlOption ReportProgressValue(int done, int total) = 0;
425 };
426 
427 
433  public:
434  struct Allocation {
438  size_t size;
439 
443  unsigned int count;
444  };
445 
449  struct Node {
455 
461 
467 
472 
478 
484 
490  std::vector<Node*> children;
491 
495  std::vector<Allocation> allocations;
496  };
497 
503  virtual Node* GetRootNode() = 0;
504 
505  virtual ~AllocationProfile() {}
506 
507  static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
508  static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
509 };
510 
511 
517  public:
524  typedef RetainedObjectInfo* (*WrapperInfoCallback)(uint16_t class_id,
525  Local<Value> wrapper);
526 
528  int GetSnapshotCount();
529 
531  const HeapSnapshot* GetHeapSnapshot(int index);
532 
537  SnapshotObjectId GetObjectId(Local<Value> value);
538 
543  Local<Value> FindObjectById(SnapshotObjectId id);
544 
550  void ClearObjectIds();
551 
557  static const SnapshotObjectId kUnknownObjectId = 0;
558 
563  public:
568  virtual const char* GetName(Local<Object> object) = 0;
569 
570  protected:
571  virtual ~ObjectNameResolver() {}
572  };
573 
577  const HeapSnapshot* TakeHeapSnapshot(
578  ActivityControl* control = NULL,
579  ObjectNameResolver* global_object_name_resolver = NULL);
580 
590  void StartTrackingHeapObjects(bool track_allocations = false);
591 
605  SnapshotObjectId GetHeapStats(OutputStream* stream,
606  int64_t* timestamp_us = NULL);
607 
613  void StopTrackingHeapObjects();
614 
642  bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024,
643  int stack_depth = 16);
644 
648  void StopSamplingHeapProfiler();
649 
656  AllocationProfile* GetAllocationProfile();
657 
662  void DeleteAllHeapSnapshots();
663 
665  void SetWrapperClassInfoProvider(
666  uint16_t class_id,
667  WrapperInfoCallback callback);
668 
674  static const uint16_t kPersistentHandleNoClassId = 0;
675 
677  size_t GetProfilerMemorySize();
678 
682  void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
683 
684  private:
685  HeapProfiler();
686  ~HeapProfiler();
687  HeapProfiler(const HeapProfiler&);
688  HeapProfiler& operator=(const HeapProfiler&);
689 };
690 
691 
716 class V8_EXPORT RetainedObjectInfo { // NOLINT
717  public:
719  virtual void Dispose() = 0;
720 
722  virtual bool IsEquivalent(RetainedObjectInfo* other) = 0;
723 
728  virtual intptr_t GetHash() = 0;
729 
734  virtual const char* GetLabel() = 0;
735 
745  virtual const char* GetGroupLabel() { return GetLabel(); }
746 
751  virtual intptr_t GetElementCount() { return -1; }
752 
754  virtual intptr_t GetSizeInBytes() { return -1; }
755 
756  protected:
758  virtual ~RetainedObjectInfo() {}
759 
760  private:
762  RetainedObjectInfo& operator=(const RetainedObjectInfo&);
763 };
764 
765 
771  HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
772  : index(index), count(count), size(size) { }
773  uint32_t index; // Index of the time interval that was changed.
774  uint32_t count; // New value of count field for the interval with this index.
775  uint32_t size; // New value of size field for the interval with this index.
776 };
777 
778 
779 } // namespace v8
780 
781 
782 #endif // V8_V8_PROFILER_H_
virtual ~OutputStream()
Definition: v8-profiler.h:325
std::vector< Node * > children
Definition: v8-profiler.h:490
Definition: libplatform.h:10
virtual int GetChunkSize()
Definition: v8-profiler.h:329
HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
Definition: v8-profiler.h:771
std::vector< CpuProfileDeoptFrame > stack
Definition: v8-profiler.h:38
virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate *data, int count)
Definition: v8-profiler.h:341
virtual ~RetainedObjectInfo()
Definition: v8-profiler.h:758
virtual ~ActivityControl()
Definition: v8-profiler.h:419
std::vector< Allocation > allocations
Definition: v8-profiler.h:495
virtual ~AllocationProfile()
Definition: v8-profiler.h:505
const char * deopt_reason
Definition: v8-profiler.h:37
uint32_t SnapshotObjectId
Definition: v8-profiler.h:17
virtual intptr_t GetElementCount()
Definition: v8-profiler.h:751
virtual intptr_t GetSizeInBytes()
Definition: v8-profiler.h:754
Local< String > script_name
Definition: v8-profiler.h:460
#define V8_EXPORT
Definition: v8.h:60
Definition: v8.h:113
virtual const char * GetGroupLabel()
Definition: v8-profiler.h:745