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.
5 #ifndef V8_PROFILER_HEAP_PROFILER_H_
6 #define V8_PROFILER_HEAP_PROFILER_H_
8 #include "src/base/smart-pointers.h"
9 #include "src/isolate.h"
15 // Forward declarations.
16 class AllocationTracker;
23 explicit HeapProfiler(Heap* heap);
26 size_t GetMemorySizeUsedByProfiler();
28 HeapSnapshot* TakeSnapshot(
29 v8::ActivityControl* control,
30 v8::HeapProfiler::ObjectNameResolver* resolver);
32 void StartHeapObjectsTracking(bool track_allocations);
33 void StopHeapObjectsTracking();
34 AllocationTracker* allocation_tracker() const {
35 return allocation_tracker_.get();
37 HeapObjectsMap* heap_object_map() const { return ids_.get(); }
38 StringsStorage* names() const { return names_.get(); }
40 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream,
41 int64_t* timestamp_us);
42 int GetSnapshotsCount();
43 HeapSnapshot* GetSnapshot(int index);
44 SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
45 void DeleteAllSnapshots();
46 void RemoveSnapshot(HeapSnapshot* snapshot);
48 void ObjectMoveEvent(Address from, Address to, int size);
50 void AllocationEvent(Address addr, int size);
52 void UpdateObjectSizeEvent(Address addr, int size);
54 void DefineWrapperClass(
55 uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback);
57 v8::RetainedObjectInfo* ExecuteWrapperClassCallback(uint16_t class_id,
59 void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
61 bool is_tracking_object_moves() const { return is_tracking_object_moves_; }
62 bool is_tracking_allocations() const {
63 return !allocation_tracker_.is_empty();
66 Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id);
67 void ClearHeapObjectMap();
72 // Mapping from HeapObject addresses to objects' uids.
73 base::SmartPointer<HeapObjectsMap> ids_;
74 List<HeapSnapshot*> snapshots_;
75 base::SmartPointer<StringsStorage> names_;
76 List<v8::HeapProfiler::WrapperInfoCallback> wrapper_callbacks_;
77 base::SmartPointer<AllocationTracker> allocation_tracker_;
78 bool is_tracking_object_moves_;
79 base::Mutex profiler_mutex_;
82 } // namespace internal
85 #endif // V8_PROFILER_HEAP_PROFILER_H_