v8  4.6.85(node5.12.0)
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"
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 
212  void SetIdle(bool is_idle);
213 
214  private:
215  CpuProfiler();
216  ~CpuProfiler();
217  CpuProfiler(const CpuProfiler&);
218  CpuProfiler& operator=(const CpuProfiler&);
219 };
220 
221 
227  public:
228  enum Type {
229  kContextVariable = 0, // A variable from a function context.
230  kElement = 1, // An element of an array.
231  kProperty = 2, // A named object property.
232  kInternal = 3, // A link that can't be accessed from JS,
233  // thus, its name isn't a real property name
234  // (e.g. parts of a ConsString).
235  kHidden = 4, // A link that is needed for proper sizes
236  // calculation, but may be hidden from user.
237  kShortcut = 5, // A link that must not be followed during
238  // sizes calculation.
239  kWeak = 6 // A weak reference (ignored by the GC).
240  };
241 
243  Type GetType() const;
244 
249  Local<Value> GetName() const;
250 
252  const HeapGraphNode* GetFromNode() const;
253 
255  const HeapGraphNode* GetToNode() const;
256 };
257 
258 
263  public:
264  enum Type {
265  kHidden = 0, // Hidden node, may be filtered when shown to user.
266  kArray = 1, // An array of elements.
267  kString = 2, // A string.
268  kObject = 3, // A JS object (except for arrays and strings).
269  kCode = 4, // Compiled code.
270  kClosure = 5, // Function closure.
271  kRegExp = 6, // RegExp.
272  kHeapNumber = 7, // Number stored in the heap.
273  kNative = 8, // Native object (not from V8 heap).
274  kSynthetic = 9, // Synthetic object, usualy used for grouping
275  // snapshot items together.
276  kConsString = 10, // Concatenated string. A pair of pointers to strings.
277  kSlicedString = 11, // Sliced string. A fragment of another string.
278  kSymbol = 12, // A Symbol (ES6).
279  kSimdValue = 13 // A SIMD value stored in the heap (Proposed ES7).
280  };
281 
283  Type GetType() const;
284 
290  Local<String> GetName() const;
291 
296  SnapshotObjectId GetId() const;
297 
299  size_t GetShallowSize() const;
300 
302  int GetChildrenCount() const;
303 
305  const HeapGraphEdge* GetChild(int index) const;
306 };
307 
308 
312 class V8_EXPORT OutputStream { // NOLINT
313  public:
314  enum WriteResult {
315  kContinue = 0,
316  kAbort = 1
317  };
318  virtual ~OutputStream() {}
320  virtual void EndOfStream() = 0;
322  virtual int GetChunkSize() { return 1024; }
328  virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
334  virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
335  return kAbort;
336  }
337 };
338 
339 
344  public:
346  kJSON = 0 // See format description near 'Serialize' method.
347  };
348 
350  const HeapGraphNode* GetRoot() const;
351 
353  const HeapGraphNode* GetNodeById(SnapshotObjectId id) const;
354 
356  int GetNodesCount() const;
357 
359  const HeapGraphNode* GetNode(int index) const;
360 
362  SnapshotObjectId GetMaxSnapshotJSObjectId() const;
363 
369  void Delete();
370 
397  void Serialize(OutputStream* stream,
398  SerializationFormat format = kJSON) const;
399 };
400 
401 
406 class V8_EXPORT ActivityControl { // NOLINT
407  public:
409  kContinue = 0,
410  kAbort = 1
411  };
412  virtual ~ActivityControl() {}
417  virtual ControlOption ReportProgressValue(int done, int total) = 0;
418 };
419 
420 
426  public:
433  typedef RetainedObjectInfo* (*WrapperInfoCallback)(uint16_t class_id,
434  Local<Value> wrapper);
435 
437  int GetSnapshotCount();
438 
440  const HeapSnapshot* GetHeapSnapshot(int index);
441 
446  SnapshotObjectId GetObjectId(Local<Value> value);
447 
452  Local<Value> FindObjectById(SnapshotObjectId id);
453 
459  void ClearObjectIds();
460 
466  static const SnapshotObjectId kUnknownObjectId = 0;
467 
472  public:
477  virtual const char* GetName(Local<Object> object) = 0;
478 
479  protected:
480  virtual ~ObjectNameResolver() {}
481  };
482 
486  const HeapSnapshot* TakeHeapSnapshot(
487  ActivityControl* control = NULL,
488  ObjectNameResolver* global_object_name_resolver = NULL);
489 
499  void StartTrackingHeapObjects(bool track_allocations = false);
500 
514  SnapshotObjectId GetHeapStats(OutputStream* stream,
515  int64_t* timestamp_us = NULL);
516 
522  void StopTrackingHeapObjects();
523 
528  void DeleteAllHeapSnapshots();
529 
531  void SetWrapperClassInfoProvider(
532  uint16_t class_id,
533  WrapperInfoCallback callback);
534 
540  static const uint16_t kPersistentHandleNoClassId = 0;
541 
543  size_t GetProfilerMemorySize();
544 
548  void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
549 
550  private:
551  HeapProfiler();
552  ~HeapProfiler();
553  HeapProfiler(const HeapProfiler&);
554  HeapProfiler& operator=(const HeapProfiler&);
555 };
556 
557 
582 class V8_EXPORT RetainedObjectInfo { // NOLINT
583  public:
585  virtual void Dispose() = 0;
586 
588  virtual bool IsEquivalent(RetainedObjectInfo* other) = 0;
589 
594  virtual intptr_t GetHash() = 0;
595 
600  virtual const char* GetLabel() = 0;
601 
611  virtual const char* GetGroupLabel() { return GetLabel(); }
612 
617  virtual intptr_t GetElementCount() { return -1; }
618 
620  virtual intptr_t GetSizeInBytes() { return -1; }
621 
622  protected:
624  virtual ~RetainedObjectInfo() {}
625 
626  private:
628  RetainedObjectInfo& operator=(const RetainedObjectInfo&);
629 };
630 
631 
637  HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
638  : index(index), count(count), size(size) { }
639  uint32_t index; // Index of the time interval that was changed.
640  uint32_t count; // New value of count field for the interval with this index.
641  uint32_t size; // New value of size field for the interval with this index.
642 };
643 
644 
645 } // namespace v8
646 
647 
648 #endif // V8_V8_PROFILER_H_
virtual ~OutputStream()
Definition: v8-profiler.h:318
Definition: libplatform.h:10
virtual int GetChunkSize()
Definition: v8-profiler.h:322
HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
Definition: v8-profiler.h:637
std::vector< CpuProfileDeoptFrame > stack
Definition: v8-profiler.h:38
virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate *data, int count)
Definition: v8-profiler.h:334
virtual ~RetainedObjectInfo()
Definition: v8-profiler.h:624
virtual ~ActivityControl()
Definition: v8-profiler.h:412
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:617
virtual intptr_t GetSizeInBytes()
Definition: v8-profiler.h:620
#define V8_EXPORT
Definition: v8.h:58
Definition: v8.h:109
virtual const char * GetGroupLabel()
Definition: v8-profiler.h:611