V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
heap-profiler.h
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 <memory>
9 #include <vector>
10 
11 #include "include/v8-profiler.h"
12 #include "src/base/platform/mutex.h"
13 #include "src/debug/debug-interface.h"
14 #include "src/globals.h"
15 #include "src/heap/heap.h"
16 
17 namespace v8 {
18 namespace internal {
19 
20 // Forward declarations.
21 class AllocationTracker;
22 class HeapObjectsMap;
23 class HeapSnapshot;
24 class SamplingHeapProfiler;
25 class StringsStorage;
26 
28  public:
29  explicit HeapProfiler(Heap* heap);
30  ~HeapProfiler() override;
31 
32  HeapSnapshot* TakeSnapshot(
33  v8::ActivityControl* control,
35 
36  bool StartSamplingHeapProfiler(uint64_t sample_interval, int stack_depth,
37  v8::HeapProfiler::SamplingFlags);
38  void StopSamplingHeapProfiler();
39  bool is_sampling_allocations() { return !!sampling_heap_profiler_; }
40  AllocationProfile* GetAllocationProfile();
41 
42  void StartHeapObjectsTracking(bool track_allocations);
43  void StopHeapObjectsTracking();
44  AllocationTracker* allocation_tracker() const {
45  return allocation_tracker_.get();
46  }
47  HeapObjectsMap* heap_object_map() const { return ids_.get(); }
48  StringsStorage* names() const { return names_.get(); }
49 
50  SnapshotObjectId PushHeapObjectsStats(OutputStream* stream,
51  int64_t* timestamp_us);
52  int GetSnapshotsCount();
53  HeapSnapshot* GetSnapshot(int index);
54  SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
55  void DeleteAllSnapshots();
56  void RemoveSnapshot(HeapSnapshot* snapshot);
57 
58  void ObjectMoveEvent(Address from, Address to, int size);
59 
60  void AllocationEvent(Address addr, int size) override;
61 
62  void UpdateObjectSizeEvent(Address addr, int size) override;
63 
64  void DefineWrapperClass(
65  uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback);
66 
67  v8::RetainedObjectInfo* ExecuteWrapperClassCallback(uint16_t class_id,
68  Object** wrapper);
69 
70  void SetGetRetainerInfosCallback(
72  v8::HeapProfiler::RetainerInfos GetRetainerInfos(Isolate* isolate);
73 
74  void AddBuildEmbedderGraphCallback(
76  void RemoveBuildEmbedderGraphCallback(
78  void BuildEmbedderGraph(Isolate* isolate, v8::EmbedderGraph* graph);
79  bool HasBuildEmbedderGraphCallback() {
80  return !build_embedder_graph_callbacks_.empty();
81  }
82 
83  bool is_tracking_object_moves() const { return is_tracking_object_moves_; }
84 
85  Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id);
86  void ClearHeapObjectMap();
87 
88  Isolate* isolate() const;
89 
90  void QueryObjects(Handle<Context> context,
91  debug::QueryObjectPredicate* predicate,
93 
94  private:
95  void MaybeClearStringsStorage();
96 
97  Heap* heap() const;
98 
99  // Mapping from HeapObject addresses to objects' uids.
100  std::unique_ptr<HeapObjectsMap> ids_;
101  std::vector<std::unique_ptr<HeapSnapshot>> snapshots_;
102  std::unique_ptr<StringsStorage> names_;
103  std::vector<v8::HeapProfiler::WrapperInfoCallback> wrapper_callbacks_;
104  std::unique_ptr<AllocationTracker> allocation_tracker_;
105  bool is_tracking_object_moves_;
106  base::Mutex profiler_mutex_;
107  std::unique_ptr<SamplingHeapProfiler> sampling_heap_profiler_;
108  v8::HeapProfiler::GetRetainerInfosCallback get_retainer_infos_callback_ =
109  nullptr;
110  std::vector<std::pair<v8::HeapProfiler::BuildEmbedderGraphCallback, void*>>
111  build_embedder_graph_callbacks_;
112 
113  DISALLOW_COPY_AND_ASSIGN(HeapProfiler);
114 };
115 
116 } // namespace internal
117 } // namespace v8
118 
119 #endif // V8_PROFILER_HEAP_PROFILER_H_
RetainerInfos(* GetRetainerInfosCallback)(v8::Isolate *isolate)
Definition: v8-profiler.h:765
Definition: libplatform.h:13
void(* BuildEmbedderGraphCallback)(v8::Isolate *isolate, v8::EmbedderGraph *graph, void *data)
Definition: v8-profiler.h:782
RetainedObjectInfo *(* WrapperInfoCallback)(uint16_t class_id, Local< Value > wrapper)
Definition: v8-profiler.h:773