Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 19 | class SamplingHeapProfiler; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 33 | bool StartSamplingHeapProfiler(uint64_t sample_interval, int stack_depth); |
| 34 | void StopSamplingHeapProfiler(); |
| 35 | bool is_sampling_allocations() { return !sampling_heap_profiler_.is_empty(); } |
| 36 | AllocationProfile* GetAllocationProfile(); |
| 37 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 38 | void StartHeapObjectsTracking(bool track_allocations); |
| 39 | void StopHeapObjectsTracking(); |
| 40 | AllocationTracker* allocation_tracker() const { |
| 41 | return allocation_tracker_.get(); |
| 42 | } |
| 43 | HeapObjectsMap* heap_object_map() const { return ids_.get(); } |
| 44 | StringsStorage* names() const { return names_.get(); } |
| 45 | |
| 46 | SnapshotObjectId PushHeapObjectsStats(OutputStream* stream, |
| 47 | int64_t* timestamp_us); |
| 48 | int GetSnapshotsCount(); |
| 49 | HeapSnapshot* GetSnapshot(int index); |
| 50 | SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj); |
| 51 | void DeleteAllSnapshots(); |
| 52 | void RemoveSnapshot(HeapSnapshot* snapshot); |
| 53 | |
| 54 | void ObjectMoveEvent(Address from, Address to, int size); |
| 55 | |
| 56 | void AllocationEvent(Address addr, int size); |
| 57 | |
| 58 | void UpdateObjectSizeEvent(Address addr, int size); |
| 59 | |
| 60 | void DefineWrapperClass( |
| 61 | uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback); |
| 62 | |
| 63 | v8::RetainedObjectInfo* ExecuteWrapperClassCallback(uint16_t class_id, |
| 64 | Object** wrapper); |
| 65 | void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info); |
| 66 | |
| 67 | bool is_tracking_object_moves() const { return is_tracking_object_moves_; } |
| 68 | bool is_tracking_allocations() const { |
| 69 | return !allocation_tracker_.is_empty(); |
| 70 | } |
| 71 | |
| 72 | Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id); |
| 73 | void ClearHeapObjectMap(); |
| 74 | |
| 75 | Isolate* isolate() const { return heap()->isolate(); } |
| 76 | |
| 77 | private: |
| 78 | Heap* heap() const; |
| 79 | |
| 80 | // Mapping from HeapObject addresses to objects' uids. |
| 81 | base::SmartPointer<HeapObjectsMap> ids_; |
| 82 | List<HeapSnapshot*> snapshots_; |
| 83 | base::SmartPointer<StringsStorage> names_; |
| 84 | List<v8::HeapProfiler::WrapperInfoCallback> wrapper_callbacks_; |
| 85 | base::SmartPointer<AllocationTracker> allocation_tracker_; |
| 86 | bool is_tracking_object_moves_; |
| 87 | base::Mutex profiler_mutex_; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 88 | base::SmartPointer<SamplingHeapProfiler> sampling_heap_profiler_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace internal |
| 92 | } // namespace v8 |
| 93 | |
| 94 | #endif // V8_PROFILER_HEAP_PROFILER_H_ |