v8  3.28.71(node0.12.18)
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 "v8.h"
9 
13 namespace v8 {
14 
15 class HeapGraphNode;
17 
18 typedef uint32_t SnapshotObjectId;
19 
24  public:
26  Handle<String> GetFunctionName() const;
27 
29  int GetScriptId() const;
30 
32  Handle<String> GetScriptResourceName() const;
33 
38  int GetLineNumber() const;
39 
44  int GetColumnNumber() const;
45 
49  const char* GetBailoutReason() const;
50 
54  unsigned GetHitCount() const;
55 
57  unsigned GetCallUid() const;
58 
60  unsigned GetNodeId() const;
61 
63  int GetChildrenCount() const;
64 
66  const CpuProfileNode* GetChild(int index) const;
67 
68  static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
69  static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
70 };
71 
72 
78  public:
80  Handle<String> GetTitle() const;
81 
83  const CpuProfileNode* GetTopDownRoot() const;
84 
89  int GetSamplesCount() const;
90 
95  const CpuProfileNode* GetSample(int index) const;
96 
102  int64_t GetSampleTimestamp(int index) const;
103 
108  int64_t GetStartTime() const;
109 
115  int64_t GetEndTime() const;
116 
121  void Delete();
122 };
123 
124 
130  public:
136  void SetSamplingInterval(int us);
137 
149  void StartProfiling(Handle<String> title, bool record_samples = false);
150 
152  V8_DEPRECATED("Use StartProfiling",
153  void StartCpuProfiling(Handle<String> title,
154  bool record_samples = false));
155 
160  CpuProfile* StopProfiling(Handle<String> title);
161 
163  V8_DEPRECATED("Use StopProfiling",
164  const CpuProfile* StopCpuProfiling(Handle<String> title));
165 
169  void SetIdle(bool is_idle);
170 
171  private:
172  CpuProfiler();
173  ~CpuProfiler();
174  CpuProfiler(const CpuProfiler&);
175  CpuProfiler& operator=(const CpuProfiler&);
176 };
177 
178 
184  public:
185  enum Type {
186  kContextVariable = 0, // A variable from a function context.
187  kElement = 1, // An element of an array.
188  kProperty = 2, // A named object property.
189  kInternal = 3, // A link that can't be accessed from JS,
190  // thus, its name isn't a real property name
191  // (e.g. parts of a ConsString).
192  kHidden = 4, // A link that is needed for proper sizes
193  // calculation, but may be hidden from user.
194  kShortcut = 5, // A link that must not be followed during
195  // sizes calculation.
196  kWeak = 6 // A weak reference (ignored by the GC).
197  };
198 
200  Type GetType() const;
201 
206  Handle<Value> GetName() const;
207 
209  const HeapGraphNode* GetFromNode() const;
210 
212  const HeapGraphNode* GetToNode() const;
213 };
214 
215 
220  public:
221  enum Type {
222  kHidden = 0, // Hidden node, may be filtered when shown to user.
223  kArray = 1, // An array of elements.
224  kString = 2, // A string.
225  kObject = 3, // A JS object (except for arrays and strings).
226  kCode = 4, // Compiled code.
227  kClosure = 5, // Function closure.
228  kRegExp = 6, // RegExp.
229  kHeapNumber = 7, // Number stored in the heap.
230  kNative = 8, // Native object (not from V8 heap).
231  kSynthetic = 9, // Synthetic object, usualy used for grouping
232  // snapshot items together.
233  kConsString = 10, // Concatenated string. A pair of pointers to strings.
234  kSlicedString = 11, // Sliced string. A fragment of another string.
235  kSymbol = 12 // A Symbol (ES6).
236  };
237 
239  Type GetType() const;
240 
246  Handle<String> GetName() const;
247 
252  SnapshotObjectId GetId() const;
253 
255  V8_DEPRECATED("Use GetShallowSize instead",
256  int GetSelfSize() const);
257 
259  size_t GetShallowSize() const;
260 
262  int GetChildrenCount() const;
263 
265  const HeapGraphEdge* GetChild(int index) const;
266 };
267 
268 
272 class V8_EXPORT OutputStream { // NOLINT
273  public:
274  enum WriteResult {
275  kContinue = 0,
276  kAbort = 1
277  };
278  virtual ~OutputStream() {}
280  virtual void EndOfStream() = 0;
282  virtual int GetChunkSize() { return 1024; }
288  virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
294  virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
295  return kAbort;
296  }
297 };
298 
299 
304  public:
306  kJSON = 0 // See format description near 'Serialize' method.
307  };
308 
310  unsigned GetUid() const;
311 
313  Handle<String> GetTitle() const;
314 
316  const HeapGraphNode* GetRoot() const;
317 
319  const HeapGraphNode* GetNodeById(SnapshotObjectId id) const;
320 
322  int GetNodesCount() const;
323 
325  const HeapGraphNode* GetNode(int index) const;
326 
328  SnapshotObjectId GetMaxSnapshotJSObjectId() const;
329 
335  void Delete();
336 
363  void Serialize(OutputStream* stream, SerializationFormat format) const;
364 };
365 
366 
371 class V8_EXPORT ActivityControl { // NOLINT
372  public:
374  kContinue = 0,
375  kAbort = 1
376  };
377  virtual ~ActivityControl() {}
382  virtual ControlOption ReportProgressValue(int done, int total) = 0;
383 };
384 
385 
391  public:
398  typedef RetainedObjectInfo* (*WrapperInfoCallback)
399  (uint16_t class_id, Handle<Value> wrapper);
400 
402  int GetSnapshotCount();
403 
405  const HeapSnapshot* GetHeapSnapshot(int index);
406 
411  SnapshotObjectId GetObjectId(Handle<Value> value);
412 
417  Handle<Value> FindObjectById(SnapshotObjectId id);
418 
424  void ClearObjectIds();
425 
431  static const SnapshotObjectId kUnknownObjectId = 0;
432 
437  public:
442  virtual const char* GetName(Handle<Object> object) = 0;
443  protected:
444  virtual ~ObjectNameResolver() {}
445  };
446 
450  const HeapSnapshot* TakeHeapSnapshot(
451  Handle<String> title,
452  ActivityControl* control = NULL,
453  ObjectNameResolver* global_object_name_resolver = NULL);
454 
464  void StartTrackingHeapObjects(bool track_allocations = false);
465 
478  SnapshotObjectId GetHeapStats(OutputStream* stream);
479 
485  void StopTrackingHeapObjects();
486 
491  void DeleteAllHeapSnapshots();
492 
494  void SetWrapperClassInfoProvider(
495  uint16_t class_id,
496  WrapperInfoCallback callback);
497 
503  static const uint16_t kPersistentHandleNoClassId = 0;
504 
506  size_t GetProfilerMemorySize();
507 
511  void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
512 
513  private:
514  HeapProfiler();
515  ~HeapProfiler();
516  HeapProfiler(const HeapProfiler&);
517  HeapProfiler& operator=(const HeapProfiler&);
518 };
519 
520 
545 class V8_EXPORT RetainedObjectInfo { // NOLINT
546  public:
548  virtual void Dispose() = 0;
549 
551  virtual bool IsEquivalent(RetainedObjectInfo* other) = 0;
552 
557  virtual intptr_t GetHash() = 0;
558 
563  virtual const char* GetLabel() = 0;
564 
574  virtual const char* GetGroupLabel() { return GetLabel(); }
575 
580  virtual intptr_t GetElementCount() { return -1; }
581 
583  virtual intptr_t GetSizeInBytes() { return -1; }
584 
585  protected:
587  virtual ~RetainedObjectInfo() {}
588 
589  private:
591  RetainedObjectInfo& operator=(const RetainedObjectInfo&);
592 };
593 
594 
600  HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
601  : index(index), count(count), size(size) { }
602  uint32_t index; // Index of the time interval that was changed.
603  uint32_t count; // New value of count field for the interval with this index.
604  uint32_t size; // New value of size field for the interval with this index.
605 };
606 
607 
608 } // namespace v8
609 
610 
611 #endif // V8_V8_PROFILER_H_
virtual ~OutputStream()
Definition: v8-profiler.h:278
static const int kNoColumnInfo
Definition: v8.h:1201
static const int kNoLineNumberInfo
Definition: v8.h:1200
Definition: libplatform.h:10
virtual int GetChunkSize()
Definition: v8-profiler.h:282
HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
Definition: v8-profiler.h:600
virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate *data, int count)
Definition: v8-profiler.h:294
virtual ~RetainedObjectInfo()
Definition: v8-profiler.h:587
Definition: v8.h:100
virtual ~ActivityControl()
Definition: v8-profiler.h:377
#define V8_DEPRECATED(message, declarator)
Definition: v8config.h:320
uint32_t SnapshotObjectId
Definition: v8-profiler.h:16
virtual intptr_t GetElementCount()
Definition: v8-profiler.h:580
virtual intptr_t GetSizeInBytes()
Definition: v8-profiler.h:583
#define V8_EXPORT
Definition: v8.h:53
virtual const char * GetGroupLabel()
Definition: v8-profiler.h:574