blob: 32e143c74ff22ddbfce5dadd2823f5122fd64598 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
12namespace v8 {
13namespace internal {
14
15// Forward declarations.
16class AllocationTracker;
17class HeapObjectsMap;
18class HeapSnapshot;
Ben Murdoch097c5b22016-05-18 11:27:45 +010019class SamplingHeapProfiler;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000020class StringsStorage;
21
22class 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 Murdoch097c5b22016-05-18 11:27:45 +010033 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 Murdoch4a90d5f2016-03-22 12:00:34 +000038 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 Murdoch097c5b22016-05-18 11:27:45 +010088 base::SmartPointer<SamplingHeapProfiler> sampling_heap_profiler_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000089};
90
91} // namespace internal
92} // namespace v8
93
94#endif // V8_PROFILER_HEAP_PROFILER_H_