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_PROFILER_HEAP_PROFILER_H_ 6 #define V8_PROFILER_HEAP_PROFILER_H_ 7 8 #include "src/base/smart-pointers.h" 9 #include "src/isolate.h" 10 #include "src/list.h" 11 12 namespace v8 { 13 namespace internal { 14 15 // Forward declarations. 16 class AllocationTracker; 17 class HeapObjectsMap; 18 class HeapSnapshot; 19 class SamplingHeapProfiler; 20 class StringsStorage; 21 22 class HeapProfiler { 23 public: 24 explicit HeapProfiler(Heap* heap); 25 ~HeapProfiler(); 26 27 size_t GetMemorySizeUsedByProfiler(); 28 29 HeapSnapshot* TakeSnapshot( 30 v8::ActivityControl* control, 31 v8::HeapProfiler::ObjectNameResolver* resolver); 32 33 bool StartSamplingHeapProfiler(uint64_t sample_interval, int stack_depth, 34 v8::HeapProfiler::SamplingFlags); 35 void StopSamplingHeapProfiler(); is_sampling_allocations()36 bool is_sampling_allocations() { return !sampling_heap_profiler_.is_empty(); } 37 AllocationProfile* GetAllocationProfile(); 38 39 void StartHeapObjectsTracking(bool track_allocations); 40 void StopHeapObjectsTracking(); allocation_tracker()41 AllocationTracker* allocation_tracker() const { 42 return allocation_tracker_.get(); 43 } heap_object_map()44 HeapObjectsMap* heap_object_map() const { return ids_.get(); } names()45 StringsStorage* names() const { return names_.get(); } 46 47 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream, 48 int64_t* timestamp_us); 49 int GetSnapshotsCount(); 50 HeapSnapshot* GetSnapshot(int index); 51 SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj); 52 void DeleteAllSnapshots(); 53 void RemoveSnapshot(HeapSnapshot* snapshot); 54 55 void ObjectMoveEvent(Address from, Address to, int size); 56 57 void AllocationEvent(Address addr, int size); 58 59 void UpdateObjectSizeEvent(Address addr, int size); 60 61 void DefineWrapperClass( 62 uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback); 63 64 v8::RetainedObjectInfo* ExecuteWrapperClassCallback(uint16_t class_id, 65 Object** wrapper); 66 void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info); 67 is_tracking_object_moves()68 bool is_tracking_object_moves() const { return is_tracking_object_moves_; } is_tracking_allocations()69 bool is_tracking_allocations() const { 70 return !allocation_tracker_.is_empty(); 71 } 72 73 Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id); 74 void ClearHeapObjectMap(); 75 isolate()76 Isolate* isolate() const { return heap()->isolate(); } 77 78 private: 79 Heap* heap() const; 80 81 // Mapping from HeapObject addresses to objects' uids. 82 base::SmartPointer<HeapObjectsMap> ids_; 83 List<HeapSnapshot*> snapshots_; 84 base::SmartPointer<StringsStorage> names_; 85 List<v8::HeapProfiler::WrapperInfoCallback> wrapper_callbacks_; 86 base::SmartPointer<AllocationTracker> allocation_tracker_; 87 bool is_tracking_object_moves_; 88 base::Mutex profiler_mutex_; 89 base::SmartPointer<SamplingHeapProfiler> sampling_heap_profiler_; 90 }; 91 92 } // namespace internal 93 } // namespace v8 94 95 #endif // V8_PROFILER_HEAP_PROFILER_H_ 96