• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2009-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_HEAP_PROFILER_H_
6 #define V8_HEAP_PROFILER_H_
7 
8 #include "src/heap-snapshot-generator-inl.h"
9 #include "src/isolate.h"
10 #include "src/smart-pointers.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class HeapSnapshot;
16 
17 class HeapProfiler {
18  public:
19   explicit HeapProfiler(Heap* heap);
20   ~HeapProfiler();
21 
22   size_t GetMemorySizeUsedByProfiler();
23 
24   HeapSnapshot* TakeSnapshot(
25       const char* name,
26       v8::ActivityControl* control,
27       v8::HeapProfiler::ObjectNameResolver* resolver);
28   HeapSnapshot* TakeSnapshot(
29       String* name,
30       v8::ActivityControl* control,
31       v8::HeapProfiler::ObjectNameResolver* resolver);
32 
33   void StartHeapObjectsTracking(bool track_allocations);
34   void StopHeapObjectsTracking();
allocation_tracker()35   AllocationTracker* allocation_tracker() const {
36     return allocation_tracker_.get();
37   }
heap_object_map()38   HeapObjectsMap* heap_object_map() const { return ids_.get(); }
names()39   StringsStorage* names() const { return names_.get(); }
40 
41   SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
42   int GetSnapshotsCount();
43   HeapSnapshot* GetSnapshot(int index);
44   SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
45   void DeleteAllSnapshots();
46   void RemoveSnapshot(HeapSnapshot* snapshot);
47 
48   void ObjectMoveEvent(Address from, Address to, int size);
49 
50   void AllocationEvent(Address addr, int size);
51 
52   void UpdateObjectSizeEvent(Address addr, int size);
53 
54   void DefineWrapperClass(
55       uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback);
56 
57   v8::RetainedObjectInfo* ExecuteWrapperClassCallback(uint16_t class_id,
58                                                       Object** wrapper);
59   void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
60 
is_tracking_object_moves()61   bool is_tracking_object_moves() const { return is_tracking_object_moves_; }
is_tracking_allocations()62   bool is_tracking_allocations() const {
63     return !allocation_tracker_.is_empty();
64   }
65 
66   Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id);
67   void ClearHeapObjectMap();
68 
69  private:
heap()70   Heap* heap() const { return ids_->heap(); }
71 
72   // Mapping from HeapObject addresses to objects' uids.
73   SmartPointer<HeapObjectsMap> ids_;
74   List<HeapSnapshot*> snapshots_;
75   SmartPointer<StringsStorage> names_;
76   unsigned next_snapshot_uid_;
77   List<v8::HeapProfiler::WrapperInfoCallback> wrapper_callbacks_;
78   SmartPointer<AllocationTracker> allocation_tracker_;
79   bool is_tracking_object_moves_;
80 };
81 
82 } }  // namespace v8::internal
83 
84 #endif  // V8_HEAP_PROFILER_H_
85