Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1 | // Copyright 2009-2010 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_HEAP_PROFILER_H_ |
| 6 | #define V8_HEAP_PROFILER_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/heap-snapshot-generator-inl.h" |
| 9 | #include "src/isolate.h" |
| 10 | #include "src/smart-pointers.h" |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 11 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 15 | class HeapSnapshot; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 16 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 17 | class HeapProfiler { |
| 18 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 19 | explicit HeapProfiler(Heap* heap); |
| 20 | ~HeapProfiler(); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 21 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | size_t GetMemorySizeUsedByProfiler(); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 23 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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(); |
| 35 | AllocationTracker* allocation_tracker() const { |
| 36 | return allocation_tracker_.get(); |
| 37 | } |
| 38 | HeapObjectsMap* heap_object_map() const { return ids_.get(); } |
| 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); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 53 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 54 | void DefineWrapperClass( |
| 55 | uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback); |
| 56 | |
| 57 | v8::RetainedObjectInfo* ExecuteWrapperClassCallback(uint16_t class_id, |
| 58 | Object** wrapper); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 59 | void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info); |
| 60 | |
| 61 | bool is_tracking_object_moves() const { return is_tracking_object_moves_; } |
| 62 | bool is_tracking_allocations() const { |
| 63 | return !allocation_tracker_.is_empty(); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 66 | Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id); |
| 67 | void ClearHeapObjectMap(); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 68 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 69 | private: |
| 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_; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 76 | unsigned next_snapshot_uid_; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 77 | List<v8::HeapProfiler::WrapperInfoCallback> wrapper_callbacks_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 78 | SmartPointer<AllocationTracker> allocation_tracker_; |
| 79 | bool is_tracking_object_moves_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 82 | } } // namespace v8::internal |
| 83 | |
| 84 | #endif // V8_HEAP_PROFILER_H_ |