blob: 93cb57a7d1599888583bbf121a20f0b89aa00c4e [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 Murdochc5610432016-08-08 18:44:38 +010033 bool StartSamplingHeapProfiler(uint64_t sample_interval, int stack_depth,
34 v8::HeapProfiler::SamplingFlags);
Ben Murdoch097c5b22016-05-18 11:27:45 +010035 void StopSamplingHeapProfiler();
36 bool is_sampling_allocations() { return !sampling_heap_profiler_.is_empty(); }
37 AllocationProfile* GetAllocationProfile();
38
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000039 void StartHeapObjectsTracking(bool track_allocations);
40 void StopHeapObjectsTracking();
41 AllocationTracker* allocation_tracker() const {
42 return allocation_tracker_.get();
43 }
44 HeapObjectsMap* heap_object_map() const { return ids_.get(); }
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
68 bool is_tracking_object_moves() const { return is_tracking_object_moves_; }
69 bool is_tracking_allocations() const {
70 return !allocation_tracker_.is_empty();
71 }
72
73 Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id);
74 void ClearHeapObjectMap();
75
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_;
Ben Murdoch097c5b22016-05-18 11:27:45 +010089 base::SmartPointer<SamplingHeapProfiler> sampling_heap_profiler_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000090};
91
92} // namespace internal
93} // namespace v8
94
95#endif // V8_PROFILER_HEAP_PROFILER_H_