30 if (
v8_flags.sampling_heap_profiler_suppress_randomness)
31 return static_cast<intptr_t
>(rate);
36 : (next > INT_MAX ? INT_MAX :
static_cast<intptr_t
>(next));
47 size_t size,
unsigned int count)
const {
48 double scale = 1.0 / (1.0 - std::exp(-
static_cast<double>(size) /
rate_));
59 isolate_->random_number_generator()),
96 node->allocations_[
size]++;
101 samples_.emplace(sample.get(), std::move(sample));
106 Sample* sample = data.GetParameter();
108 bool is_minor_gc = Heap::IsYoungGenerationCollector(
109 heap->current_or_last_garbage_collector());
110 bool should_keep_sample =
112 ? (sample->profiler->flags_ &
114 : (sample->profiler->flags_ &
116 if (should_keep_sample) {
117 sample->global.Reset();
121 DCHECK_GT(node->allocations_[sample->size], 0);
122 node->allocations_[sample->size]--;
123 if (node->allocations_[sample->size] == 0) {
124 node->allocations_.erase(sample->size);
125 while (node->allocations_.empty() && node->children_.empty() &&
126 node->parent_ && !node->parent_->pinned_) {
129 node->script_id_, node->script_position_, node->name_);
134 sample->profiler->samples_.erase(sample);
140 int start_position) {
148 auto new_child = std::make_unique<AllocationNode>(
149 parent, name, script_id, start_position,
next_node_id());
156 std::vector<Tagged<SharedFunctionInfo>>
stack;
158 int frames_captured = 0;
159 bool found_arguments_marker_frames =
false;
169 stack.push_back(shared);
172 found_arguments_marker_frames =
true;
177 if (frames_captured == 0) {
178 const char* name =
nullptr;
179 switch (
isolate_->current_vm_state()) {
190 name =
"(BYTECODE_COMPILER)";
216 for (
auto it = stack.rbegin(); it != stack.rend(); ++it) {
218 const char* name = this->
names()->
GetCopy(shared->DebugNameCStr().get());
220 if (IsScript(shared->script())) {
222 script_id = script->id();
227 if (found_arguments_marker_frames) {
240 node->pinned_ =
true;
245 std::vector<v8::AllocationProfile::Allocation> allocations;
246 allocations.reserve(node->allocations_.size());
248 auto script_iterator = scripts.find(node->script_id_);
249 if (script_iterator != scripts.end()) {
251 if (IsName(script->name())) {
258 line = pos_info.
line + 1;
259 column = pos_info.
column + 1;
262 for (
auto alloc : node->allocations_) {
263 allocations.push_back(
ScaleSample(alloc.first, alloc.second));
269 script_name, node->script_id_, node->script_position_, line, column,
270 node->id_, std::vector<v8::AllocationProfile::Node*>(), allocations});
276 for (
const auto& it : node->children_) {
277 current->children.push_back(
280 node->pinned_ =
false;
291 std::map<int, Handle<Script>> scripts;
295 script = iterator.
Next()) {
306const std::vector<v8::AllocationProfile::Sample>
308 std::vector<v8::AllocationProfile::Sample> samples;
311 const Sample* sample = it.second.get();
interpreter::OperandScale scale
static const int kNoLineNumberInfo
static const int kNoColumnNumberInfo
@ kSamplingIncludeObjectsCollectedByMajorGC
@ kSamplingIncludeObjectsCollectedByMinorGC
static V8_INLINE Local< T > FromSlot(internal::Address *slot)
static const int kNoScriptId
double NextDouble() V8_WARN_UNUSED_RESULT
Handle< String > InternalizeUtf8String(base::Vector< const char > str)
V8_INLINE bool is_null() const
V8_INLINE Address * location() const
static V8_INLINE bool InTrustedSpace(Tagged< HeapObject > object)
static V8_INLINE bool InCodeSpace(Tagged< HeapObject > object)
static Tagged< HeapObject > FromAddress(Address address)
V8_EXPORT_PRIVATE void CollectAllGarbage(GCFlags gc_flags, GarbageCollectionReason gc_reason, const GCCallbackFlags gc_callback_flags=kNoGCCallbackFlags)
void AddAllocationObserversToAllSpaces(AllocationObserver *observer, AllocationObserver *new_space_observer)
void RemoveAllocationObserversFromAllSpaces(AllocationObserver *observer, AllocationObserver *new_space_observer)
v8::internal::Factory * factory()
Tagged< JSFunction > function() const override
Tagged< Object > unchecked_function() const
JavaScriptFrame * frame() const
V8_EXPORT_PRIVATE void Advance()
AllocationNode *const parent_
AllocationNode * FindChildNode(FunctionId id)
std::map< FunctionId, std::unique_ptr< AllocationNode > > children_
static FunctionId function_id(int script_id, int start_position, const char *name)
AllocationNode * AddChildNode(FunctionId id, std::unique_ptr< AllocationNode > node)
intptr_t GetNextSampleInterval(uint64_t rate)
base::RandomNumberGenerator *const random_
v8::HeapProfiler::SamplingFlags flags_
const std::vector< v8::AllocationProfile::Sample > BuildSamples() const
v8::AllocationProfile::Allocation ScaleSample(size_t size, unsigned int count) const
void SampleObject(Address soon_object, size_t size)
v8::AllocationProfile * GetAllocationProfile()
AllocationNode * AddStack()
AllocationNode profile_root_
static void OnWeakCallback(const WeakCallbackInfo< Sample > &data)
StringsStorage * names() const
SamplingHeapProfiler(Heap *heap, StringsStorage *names, uint64_t rate, int stack_depth, v8::HeapProfiler::SamplingFlags flags)
std::unordered_map< Sample *, std::unique_ptr< Sample > > samples_
AllocationNode * FindOrAddChildNode(AllocationNode *parent, const char *name, int script_id, int start_position)
v8::AllocationProfile::Node * TranslateAllocationNode(AllocationProfile *profile, SamplingHeapProfiler::AllocationNode *node, const std::map< int, Handle< Script > > &scripts)
uint64_t next_sample_id()
Observer allocation_observer_
StringsStorage *const names_
static bool GetPositionInfo(DirectHandle< Script > script, int position, PositionInfo *info, OffsetFlag offset_flag=OffsetFlag::kWithOffset)
const char * GetCopy(const char *src)
const char * GetName(Tagged< Name > name)
#define V8_EXTERNAL_CODE_SPACE_BOOL
ZoneStack< RpoNumber > & stack
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
constexpr int kTaggedSize
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
V8_EXPORT_PRIVATE FlagValues v8_flags
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
v8::Local< T > ToApiHandle(v8::internal::DirectHandle< v8::internal::Object > obj)
#define CHECK_GT(lhs, rhs)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
#define DCHECK_GT(v1, v2)