v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
heap-profiler.h
Go to the documentation of this file.
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"
13#include "src/common/globals.h"
15#include "src/heap/heap.h"
16
17namespace v8 {
18namespace internal {
19
20// Forward declarations.
21class AllocationTracker;
22class HeapObjectsMap;
23class HeapProfiler;
24class HeapSnapshot;
25class SamplingHeapProfiler;
26class StringsStorage;
27
28// A class which can notify the corresponding HeapProfiler when the embedder
29// heap moves its objects to different locations, so that heap snapshots can
30// generate consistent IDs for moved objects.
32 public:
34 : profiler_(profiler) {}
36 delete;
38 const HeapProfilerNativeMoveListener& other) = delete;
39
40 // The subclass's destructor implementation should stop listening.
42
43 // Functionality required in concrete subclass:
44 virtual void StartListening() = 0;
45 virtual void StopListening() = 0;
46
47 protected:
48 void ObjectMoveEvent(Address from, Address to, int size);
49
50 private:
52};
53
56
57 public:
58 explicit HeapProfiler(Heap* heap);
59 ~HeapProfiler() override;
60 HeapProfiler(const HeapProfiler&) = delete;
62
65
66 // Implementation of --heap-snapshot-on-oom.
68 HeapSnapshotMode snapshot_mode = HeapSnapshotMode::kRegular);
69 // Just takes a snapshot performing GC as part of the snapshot.
71 std::string filename);
72
73 bool StartSamplingHeapProfiler(uint64_t sample_interval, int stack_depth,
78
79 void StartHeapObjectsTracking(bool track_allocations);
84 HeapObjectsMap* heap_object_map() const { return ids_.get(); }
85 StringsStorage* names() const { return names_.get(); }
86
88 int64_t* timestamp_us);
89 int GetSnapshotsCount() const;
90 bool IsTakingSnapshot() const;
91 HeapSnapshot* GetSnapshot(int index);
94 void DeleteAllSnapshots();
95 void RemoveSnapshot(HeapSnapshot* snapshot);
96
97 std::vector<v8::Local<v8::Value>> GetDetachedJSWrapperObjects();
98
99 void ObjectMoveEvent(Address from, Address to, int size,
100 bool is_native_object);
101
102 void AllocationEvent(Address addr, int size) override;
103
104 void UpdateObjectSizeEvent(Address addr, int size) override;
105
110 void BuildEmbedderGraph(Isolate* isolate, v8::EmbedderGraph* graph);
114
118 return get_detachedness_callback_.first != nullptr;
119 }
121 const v8::Local<v8::Value> v8_value, uint16_t class_id);
122
123 const char* CopyNameForHeapSnapshot(const char* name);
124
126
128 void ClearHeapObjectMap();
129
130 Isolate* isolate() const;
131
133 QueryObjectPredicate* predicate,
134 std::vector<v8::Global<v8::Object>>* objects);
136 std::unique_ptr<HeapProfilerNativeMoveListener> listener) {
137 native_move_listener_ = std::move(listener);
139 native_move_listener_->StartListening();
140 }
141 }
142
143 private:
145
146 Heap* heap() const;
147
148 // Mapping from HeapObject addresses to objects' uids.
149 std::unique_ptr<HeapObjectsMap> ids_;
150 std::vector<std::unique_ptr<HeapSnapshot>> snapshots_;
151 std::unique_ptr<StringsStorage> names_;
152 std::unique_ptr<AllocationTracker> allocation_tracker_;
156 std::unique_ptr<SamplingHeapProfiler> sampling_heap_profiler_;
157 std::vector<std::pair<v8::HeapProfiler::BuildEmbedderGraphCallback, void*>>
159 std::pair<v8::HeapProfiler::GetDetachednessCallback, void*>
161 std::unique_ptr<HeapProfilerNativeMoveListener> native_move_listener_;
162};
163
164} // namespace internal
165} // namespace v8
166
167#endif // V8_PROFILER_HEAP_PROFILER_H_
EmbedderGraph::Node::Detachedness(*)( v8::Isolate *isolate, const v8::Local< v8::Value > &v8_value, uint16_t class_id, void *data) GetDetachednessCallback
void(*) BuildEmbedderGraphCallback(v8::Isolate *isolate, v8::EmbedderGraph *graph, void *data)
HeapProfilerNativeMoveListener & operator=(const HeapProfilerNativeMoveListener &other)=delete
HeapProfilerNativeMoveListener(const HeapProfilerNativeMoveListener &other)=delete
HeapProfilerNativeMoveListener(HeapProfiler *profiler)
void ObjectMoveEvent(Address from, Address to, int size)
void set_native_move_listener(std::unique_ptr< HeapProfilerNativeMoveListener > listener)
std::vector< std::pair< v8::HeapProfiler::BuildEmbedderGraphCallback, void * > > build_embedder_graph_callbacks_
const char * CopyNameForHeapSnapshot(const char *name)
std::vector< std::unique_ptr< HeapSnapshot > > snapshots_
std::unique_ptr< StringsStorage > names_
DirectHandle< HeapObject > FindHeapObjectById(SnapshotObjectId id)
HeapObjectsMap * heap_object_map() const
std::vector< v8::Local< v8::Value > > GetDetachedJSWrapperObjects()
HeapProfiler(const HeapProfiler &)=delete
v8::EmbedderGraph::Node::Detachedness GetDetachedness(const v8::Local< v8::Value > v8_value, uint16_t class_id)
SnapshotObjectId GetSnapshotObjectId(DirectHandle< Object > obj)
SnapshotObjectId PushHeapObjectsStats(OutputStream *stream, int64_t *timestamp_us)
std::unique_ptr< SamplingHeapProfiler > sampling_heap_profiler_
void TakeSnapshotToFile(const v8::HeapProfiler::HeapSnapshotOptions options, std::string filename)
void SetGetDetachednessCallback(v8::HeapProfiler::GetDetachednessCallback callback, void *data)
void AllocationEvent(Address addr, int size) override
HeapSnapshot * GetSnapshot(int index)
void RemoveBuildEmbedderGraphCallback(v8::HeapProfiler::BuildEmbedderGraphCallback callback, void *data)
bool HasGetDetachednessCallback() const
void StartHeapObjectsTracking(bool track_allocations)
void WriteSnapshotToDiskAfterGC(HeapSnapshotMode snapshot_mode=HeapSnapshotMode::kRegular)
std::unique_ptr< HeapObjectsMap > ids_
void ObjectMoveEvent(Address from, Address to, int size, bool is_native_object)
std::unique_ptr< HeapProfilerNativeMoveListener > native_move_listener_
void AddBuildEmbedderGraphCallback(v8::HeapProfiler::BuildEmbedderGraphCallback callback, void *data)
AllocationProfile * GetAllocationProfile()
void UpdateObjectSizeEvent(Address addr, int size) override
bool StartSamplingHeapProfiler(uint64_t sample_interval, int stack_depth, v8::HeapProfiler::SamplingFlags)
StringsStorage * names() const
void RemoveSnapshot(HeapSnapshot *snapshot)
std::unique_ptr< AllocationTracker > allocation_tracker_
AllocationTracker * allocation_tracker() const
HeapProfiler & operator=(const HeapProfiler &)=delete
void QueryObjects(DirectHandle< Context > context, QueryObjectPredicate *predicate, std::vector< v8::Global< v8::Object > > *objects)
bool is_tracking_object_moves() const
HeapSnapshot * TakeSnapshot(const v8::HeapProfiler::HeapSnapshotOptions options)
std::pair< v8::HeapProfiler::GetDetachednessCallback, void * > get_detachedness_callback_
void BuildEmbedderGraph(Isolate *isolate, v8::EmbedderGraph *graph)
std::string filename
TNode< Object > callback
void * NativeObject
Definition v8-profiler.h:30
uint32_t SnapshotObjectId
Definition v8-profiler.h:31