v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
v8-profiler.h
Go to the documentation of this file.
1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_V8_PROFILER_H_
29 #define V8_V8_PROFILER_H_
30 
31 #include "v8.h"
32 
36 namespace v8 {
37 
38 class HeapGraphNode;
40 
41 typedef uint32_t SnapshotObjectId;
42 
47  public:
49  Handle<String> GetFunctionName() const;
50 
52  int GetScriptId() const;
53 
55  Handle<String> GetScriptResourceName() const;
56 
61  int GetLineNumber() const;
62 
67  int GetColumnNumber() const;
68 
72  const char* GetBailoutReason() const;
73 
77  unsigned GetHitCount() const;
78 
80  unsigned GetCallUid() const;
81 
83  unsigned GetNodeId() const;
84 
86  int GetChildrenCount() const;
87 
89  const CpuProfileNode* GetChild(int index) const;
90 
91  static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
92  static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
93 };
94 
95 
101  public:
103  Handle<String> GetTitle() const;
104 
106  const CpuProfileNode* GetTopDownRoot() const;
107 
112  int GetSamplesCount() const;
113 
118  const CpuProfileNode* GetSample(int index) const;
119 
124  int64_t GetStartTime() const;
125 
130  int64_t GetEndTime() const;
131 
136  void Delete();
137 };
138 
139 
145  public:
151  void SetSamplingInterval(int us);
152 
164  void StartProfiling(Handle<String> title, bool record_samples = false);
165 
167  void StartCpuProfiling(Handle<String> title, bool record_samples = false);
168 
173  CpuProfile* StopProfiling(Handle<String> title);
174 
176  const CpuProfile* StopCpuProfiling(Handle<String> title);
177 
181  void SetIdle(bool is_idle);
182 
183  private:
184  CpuProfiler();
185  ~CpuProfiler();
186  CpuProfiler(const CpuProfiler&);
187  CpuProfiler& operator=(const CpuProfiler&);
188 };
189 
190 
196  public:
197  enum Type {
198  kContextVariable = 0, // A variable from a function context.
199  kElement = 1, // An element of an array.
200  kProperty = 2, // A named object property.
201  kInternal = 3, // A link that can't be accessed from JS,
202  // thus, its name isn't a real property name
203  // (e.g. parts of a ConsString).
204  kHidden = 4, // A link that is needed for proper sizes
205  // calculation, but may be hidden from user.
206  kShortcut = 5, // A link that must not be followed during
207  // sizes calculation.
208  kWeak = 6 // A weak reference (ignored by the GC).
209  };
210 
212  Type GetType() const;
213 
218  Handle<Value> GetName() const;
219 
221  const HeapGraphNode* GetFromNode() const;
222 
224  const HeapGraphNode* GetToNode() const;
225 };
226 
227 
232  public:
233  enum Type {
234  kHidden = 0, // Hidden node, may be filtered when shown to user.
235  kArray = 1, // An array of elements.
236  kString = 2, // A string.
237  kObject = 3, // A JS object (except for arrays and strings).
238  kCode = 4, // Compiled code.
239  kClosure = 5, // Function closure.
240  kRegExp = 6, // RegExp.
241  kHeapNumber = 7, // Number stored in the heap.
242  kNative = 8, // Native object (not from V8 heap).
243  kSynthetic = 9, // Synthetic object, usualy used for grouping
244  // snapshot items together.
245  kConsString = 10, // Concatenated string. A pair of pointers to strings.
246  kSlicedString = 11 // Sliced string. A fragment of another string.
247  };
248 
250  Type GetType() const;
251 
257  Handle<String> GetName() const;
258 
263  SnapshotObjectId GetId() const;
264 
266  V8_DEPRECATED("Use GetShallowSize instead",
267  int GetSelfSize() const);
268 
270  size_t GetShallowSize() const;
271 
273  int GetChildrenCount() const;
274 
276  const HeapGraphEdge* GetChild(int index) const;
277 };
278 
279 
283 class V8_EXPORT OutputStream { // NOLINT
284  public:
285  enum WriteResult {
286  kContinue = 0,
287  kAbort = 1
288  };
289  virtual ~OutputStream() {}
291  virtual void EndOfStream() = 0;
293  virtual int GetChunkSize() { return 1024; }
299  virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
305  virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
306  return kAbort;
307  };
308 };
309 
310 
315  public:
317  kJSON = 0 // See format description near 'Serialize' method.
318  };
319 
321  unsigned GetUid() const;
322 
324  Handle<String> GetTitle() const;
325 
327  const HeapGraphNode* GetRoot() const;
328 
330  const HeapGraphNode* GetNodeById(SnapshotObjectId id) const;
331 
333  int GetNodesCount() const;
334 
336  const HeapGraphNode* GetNode(int index) const;
337 
339  SnapshotObjectId GetMaxSnapshotJSObjectId() const;
340 
346  void Delete();
347 
374  void Serialize(OutputStream* stream, SerializationFormat format) const;
375 };
376 
377 
382 class V8_EXPORT ActivityControl { // NOLINT
383  public:
385  kContinue = 0,
386  kAbort = 1
387  };
388  virtual ~ActivityControl() {}
393  virtual ControlOption ReportProgressValue(int done, int total) = 0;
394 };
395 
396 
402  public:
409  typedef RetainedObjectInfo* (*WrapperInfoCallback)
410  (uint16_t class_id, Handle<Value> wrapper);
411 
413  int GetSnapshotCount();
414 
416  const HeapSnapshot* GetHeapSnapshot(int index);
417 
422  SnapshotObjectId GetObjectId(Handle<Value> value);
423 
428  Handle<Value> FindObjectById(SnapshotObjectId id);
429 
435  void ClearObjectIds();
436 
442  static const SnapshotObjectId kUnknownObjectId = 0;
443 
448  public:
453  virtual const char* GetName(Handle<Object> object) = 0;
454  protected:
455  virtual ~ObjectNameResolver() {}
456  };
457 
461  const HeapSnapshot* TakeHeapSnapshot(
462  Handle<String> title,
463  ActivityControl* control = NULL,
464  ObjectNameResolver* global_object_name_resolver = NULL);
465 
475  void StartTrackingHeapObjects(bool track_allocations = false);
476 
489  SnapshotObjectId GetHeapStats(OutputStream* stream);
490 
496  void StopTrackingHeapObjects();
497 
502  void DeleteAllHeapSnapshots();
503 
505  void SetWrapperClassInfoProvider(
506  uint16_t class_id,
507  WrapperInfoCallback callback);
508 
514  static const uint16_t kPersistentHandleNoClassId = 0;
515 
517  size_t GetProfilerMemorySize();
518 
522  void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
523 
524  private:
525  HeapProfiler();
526  ~HeapProfiler();
527  HeapProfiler(const HeapProfiler&);
528  HeapProfiler& operator=(const HeapProfiler&);
529 };
530 
531 
556 class V8_EXPORT RetainedObjectInfo { // NOLINT
557  public:
559  virtual void Dispose() = 0;
560 
562  virtual bool IsEquivalent(RetainedObjectInfo* other) = 0;
563 
568  virtual intptr_t GetHash() = 0;
569 
574  virtual const char* GetLabel() = 0;
575 
585  virtual const char* GetGroupLabel() { return GetLabel(); }
586 
591  virtual intptr_t GetElementCount() { return -1; }
592 
594  virtual intptr_t GetSizeInBytes() { return -1; }
595 
596  protected:
598  virtual ~RetainedObjectInfo() {}
599 
600  private:
602  RetainedObjectInfo& operator=(const RetainedObjectInfo&);
603 };
604 
605 
611  HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
612  : index(index), count(count), size(size) { }
613  uint32_t index; // Index of the time interval that was changed.
614  uint32_t count; // New value of count field for the interval with this index.
615  uint32_t size; // New value of size field for the interval with this index.
616 };
617 
618 
619 } // namespace v8
620 
621 
622 #endif // V8_V8_PROFILER_H_
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
virtual ~OutputStream()
Definition: v8-profiler.h:289
TypeImpl< ZoneTypeConfig > Type
static const int kNoColumnInfo
Definition: v8.h:1264
unsigned short uint16_t
Definition: unicode.cc:46
static const int kNoLineNumberInfo
Definition: v8.h:1263
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object size
virtual int GetChunkSize()
Definition: v8-profiler.h:293
HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
Definition: v8-profiler.h:611
virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate *data, int count)
Definition: v8-profiler.h:305
virtual ~RetainedObjectInfo()
Definition: v8-profiler.h:598
virtual ~ActivityControl()
Definition: v8-profiler.h:388
#define V8_EXPORT
Definition: v8.h:76
#define V8_DEPRECATED(message, declarator)
Definition: v8config.h:343
const char * GetBailoutReason(BailoutReason reason)
Definition: objects.cc:16437
uint32_t SnapshotObjectId
Definition: v8-profiler.h:39
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
virtual intptr_t GetElementCount()
Definition: v8-profiler.h:591
virtual intptr_t GetSizeInBytes()
Definition: v8-profiler.h:594
virtual const char * GetGroupLabel()
Definition: v8-profiler.h:585