5#ifndef V8_PROFILER_PROFILE_GENERATOR_H_
6#define V8_PROFILER_PROFILE_GENERATOR_H_
13#include <unordered_map>
39 void SetPosition(
int pc_offset,
int line,
int inlining_id);
40 int GetSourceLineNumber(
int pc_offset)
const;
73 std::unique_ptr<SourcePositionTable>
line_info =
nullptr,
102 std::vector<CpuProfileDeoptFrame> inlined_frames);
162 std::unordered_set<CodeEntry*, Hasher, Equals> inline_entries,
163 std::unordered_map<
int, std::vector<CodeEntryAndLineNumber>>
239 "builtin_count exceeds size of bitfield");
295 int line_number = 0);
306 void IncrementLineTicks(
int src_line);
310 const std::vector<ProfileNode*>*
children()
const {
return &children_list_; }
311 unsigned id()
const {
return id_; }
314 return line_number_ != 0 ? line_number_ :
entry_->line_number();
319 return static_cast<unsigned int>(line_ticks_.size());
322 unsigned int length)
const;
329 void Print(
int indent)
const;
348 std::unordered_map<CodeEntryAndLineNumber, ProfileNode*, Hasher, Equals>
372 const std::vector<CodeEntry*>& path,
374 bool update_stats =
true);
378 bool update_stats =
true,
383 void Print()
const { root_->Print(0); }
390 return std::move(pending_nodes_);
396 template <
typename Callback>
397 void TraverseDepthFirst(Callback*
callback);
423 std::unique_ptr<DiscardedSamplesDelegate> delegate =
nullptr);
432 int src_line,
bool update_stats,
435 const std::optional<uint64_t> trace_id = std::nullopt);
445 return options_.sampling_interval_us();
480 std::unique_ptr<DiscardedSamplesDelegate> delegate)
498 void AddCode(Address addr,
CodeEntry* entry,
unsigned size);
499 void MoveCode(Address from, Address to);
503 void ClearCodesInRange(Address
start, Address
end);
504 CodeEntry* FindEntry(Address addr, Address* out_instruction_start =
nullptr);
506 size_t size()
const {
return code_map_.size(); }
508 size_t GetEstimatedMemoryUsage()
const;
528 template <
typename... Args>
553 std::unique_ptr<DiscardedSamplesDelegate> delegate =
nullptr);
561 std::vector<std::unique_ptr<CpuProfile>>*
profiles() {
562 return &finished_profiles_;
565 return resource_names_.GetName(name);
575 void AddPathToCurrentProfiles(
579 Address native_context_address = kNullAddress,
580 Address native_embedder_context_address = kNullAddress,
581 const std::optional<uint64_t> trace_id = std::nullopt);
584 void UpdateNativeContextAddressForCurrentProfiles(Address from, Address to);
587 static const int kMaxSimultaneousProfiles = 100;
593 std::unique_ptr<DiscardedSamplesDelegate> delegate =
nullptr);
static const int kNoColumnNumberInfo
static const int kNoLineNumberInfo
static constexpr U kNumValues
static constexpr T decode(U value)
static V8_NODISCARD constexpr U update(U previous, T value)
static constexpr int kBuiltinCount
StringsStorage & strings()
StringsStorage function_and_resource_names_
static CodeEntry * Create(Args &&... args)
static const char *const kNoDeoptReason
LogEventListener::CodeTag code_tag() const
static V8_EXPORT_PRIVATE const char *const kUnresolvedFunctionName
bool is_ref_counted() const
bool IsSameFunctionAs(const CodeEntry *entry) const
bool has_deopt_info() const
std::atomic< std::size_t > ref_count_
void FillFunctionInfo(Tagged< SharedFunctionInfo > shared)
Address ** heap_object_location_address()
const SourcePositionTable * line_info() const
const char * bailout_reason() const
void set_script_id(int script_id)
std::unique_ptr< RareData > rare_data_
CodeEntry & operator=(const CodeEntry &)=delete
CodeEntry(const CodeEntry &)=delete
static V8_EXPORT_PRIVATE const char *const kIdleEntryName
CodeEntry(LogEventListener::CodeTag tag, const char *name, const char *resource_name=CodeEntry::kEmptyResourceName, int line_number=v8::CpuProfileNode::kNoLineNumberInfo, int column_number=v8::CpuProfileNode::kNoColumnNumberInfo, std::unique_ptr< SourcePositionTable > line_info=nullptr, bool is_shared_cross_origin=false, CodeType code_type=CodeType::JS)
void SetInlineStacks(std::unordered_set< CodeEntry *, Hasher, Equals > inline_entries, std::unordered_map< int, std::vector< CodeEntryAndLineNumber > > inline_stacks)
static V8_EXPORT_PRIVATE CodeEntry * gc_entry()
LogEventListener::Event event() const
int column_number() const
static V8_EXPORT_PRIVATE const char *const kGarbageCollectorEntryName
Address * heap_object_location_
void set_bailout_reason(const char *bailout_reason)
bool is_shared_cross_origin() const
CpuProfileDeoptInfo GetDeoptInfo()
const char * name() const
static V8_EXPORT_PRIVATE CodeEntry * root_entry()
const std::vector< CodeEntryAndLineNumber > * GetInlineStack(int pc_offset) const
std::unique_ptr< SourcePositionTable > line_info_
void set_position(int position)
RareData * EnsureRareData()
void ReleaseStrings(StringsStorage &strings)
static V8_EXPORT_PRIVATE const char *const kEmptyResourceName
void SetBuiltinId(Builtin id)
static V8_EXPORT_PRIVATE CodeEntry * program_entry()
const char * resource_name_
Address instruction_start_
const char * code_type_string() const
size_t EstimatedSize() const
static const char *const kEmptyBailoutReason
void set_instruction_start(Address address)
static V8_EXPORT_PRIVATE CodeEntry * idle_entry()
int GetSourceLine(int pc_offset) const
static V8_EXPORT_PRIVATE const char *const kRootEntryName
void set_deopt_info(const char *deopt_reason, int deopt_id, std::vector< CpuProfileDeoptFrame > inlined_frames)
static V8_EXPORT_PRIVATE CodeEntry * unresolved_entry()
const char * resource_name() const
static V8_EXPORT_PRIVATE const char *const kProgramEntryName
Address instruction_start() const
Address native_context_address_
void set_native_context_address(Address address)
ContextFilter(Address native_context_address=kNullAddress)
bool Accept(Address native_context_address) const
void OnMoveEvent(Address from_address, Address to_address)
Address native_context_address() const
void SerializeTimeDeltas()
CpuProfileJSONSerializer & operator=(const CpuProfileJSONSerializer &)=delete
static const int kEdgeFieldsCount
OutputStreamWriter * writer_
CpuProfileJSONSerializer(const CpuProfileJSONSerializer &)=delete
void SerializeNode(const v8::CpuProfileNode *node)
void SerializeChildren(const v8::CpuProfileNode *node, int childrenCount)
static const int kNodeFieldsCount
void Serialize(v8::OutputStream *stream)
void SerializeCallFrame(const v8::CpuProfileNode *node)
CpuProfileJSONSerializer(CpuProfile *profile)
void SerializePositionTicks(const v8::CpuProfileNode *node, int lineCount)
std::unique_ptr< DiscardedSamplesDelegate > delegate_
CpuProfileMaxSamplesCallbackTask(std::unique_ptr< DiscardedSamplesDelegate > delegate)
const ProfileTree * top_down() const
base::TimeTicks end_time_
std::unique_ptr< DiscardedSamplesDelegate > delegate_
int64_t sampling_interval_us() const
const CpuProfilingOptions options_
base::TimeTicks start_time() const
base::TimeTicks start_time_
void AddPath(base::TimeTicks timestamp, const ProfileStackTrace &path, int src_line, bool update_stats, base::TimeDelta sampling_interval, StateTag state, EmbedderStateTag embedder_state, const std::optional< uint64_t > trace_id=std::nullopt)
ContextFilter & context_filter()
ContextFilter context_filter_
std::deque< SampleInfo > samples_
CpuProfile(const CpuProfile &)=delete
const char * title() const
CpuProfile & operator=(const CpuProfile &)=delete
V8_EXPORT_PRIVATE bool CheckSubsample(base::TimeDelta sampling_interval)
int samples_count() const
CpuProfiler * cpu_profiler() const
base::TimeTicks end_time() const
void StreamPendingTraceEvents()
const SampleInfo & sample(int index) const
size_t streaming_next_sample_
V8_EXPORT_PRIVATE CpuProfile(CpuProfiler *profiler, ProfilerId id, const char *title, CpuProfilingOptions options, std::unique_ptr< DiscardedSamplesDelegate > delegate=nullptr)
V8_EXPORT_PRIVATE void Print() const
base::TimeDelta next_sample_delta_
CpuProfiler *const profiler_
base::RecursiveMutex current_profiles_mutex_
const char * GetName(Tagged< Name > name)
std::vector< std::unique_ptr< CpuProfile > > finished_profiles_
CpuProfilesCollection & operator=(const CpuProfilesCollection &)=delete
std::vector< std::unique_ptr< CpuProfile > > * profiles()
StringsStorage resource_names_
CpuProfilesCollection(const CpuProfilesCollection &)=delete
static std::atomic< ProfilerId > last_id_
void set_cpu_profiler(CpuProfiler *profiler)
std::vector< std::unique_ptr< CpuProfile > > current_profiles_
CodeEntryStorage & code_entries()
std::multimap< Address, CodeEntryMapInfo > code_map_
InstructionStreamMap(const InstructionStreamMap &)=delete
CodeEntryStorage & code_entries_
InstructionStreamMap & operator=(const InstructionStreamMap &)=delete
std::vector< CpuProfileDeoptInfo > deopt_infos_
ProfileNode(const ProfileNode &)=delete
ProfileNode * parent() const
std::unordered_map< int, int > line_ticks_
unsigned int GetHitLineCount() const
unsigned self_ticks() const
void IncrementSelfTicks()
const std::vector< ProfileNode * > * children() const
CodeEntry * entry() const
const std::vector< CpuProfileDeoptInfo > & deopt_infos() const
std::unordered_map< CodeEntryAndLineNumber, ProfileNode *, Hasher, Equals > children_
std::vector< ProfileNode * > children_list_
ProfileNode & operator=(const ProfileNode &)=delete
void IncreaseSelfTicks(unsigned amount)
CodeEntryStorage * code_entries()
std::vector< const ProfileNode * > pending_nodes_
CodeEntryStorage *const code_entries_
ProfileNode * root() const
ProfileTree & operator=(const ProfileTree &)=delete
Isolate * isolate() const
size_t pending_nodes_count() const
void EnqueueNode(const ProfileNode *node)
ProfileTree(const ProfileTree &)=delete
std::vector< const ProfileNode * > TakePendingNodes()
SourcePositionTable(const SourcePositionTable &)=delete
SourcePositionTable & operator=(const SourcePositionTable &)=delete
SourcePositionTable()=default
std::vector< SourcePositionTuple > pc_offsets_to_lines_
base::Vector< const DirectHandle< Object > > args
ZoneVector< Entry > entries
uint32_t ComputeUnseededHash(uint32_t key)
static constexpr Address kNullAddress
std::vector< CodeEntryAndLineNumber > ProfileStackTrace
constexpr int kNoDeoptimizationId
BytecodeSequenceNode * parent_
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
#define DCHECK_GT(v1, v2)
#define V8_EXPORT_PRIVATE
bool operator()(const CodeEntry *lhs, const CodeEntry *rhs) const
std::size_t operator()(CodeEntry *e) const
std::vector< CpuProfileDeoptFrame > deopt_inlined_frames_
const char * bailout_reason_
const char * deopt_reason_
std::unordered_map< int, std::vector< CodeEntryAndLineNumber > > inline_stacks_
std::unordered_set< CodeEntry *, Hasher, Equals > inline_entries_
EmbedderStateTag embedder_state_tag
base::TimeTicks timestamp
const std::optional< uint64_t > trace_id
bool operator()(CodeEntryAndLineNumber lhs, CodeEntryAndLineNumber rhs) const
std::size_t operator()(CodeEntryAndLineNumber pair) const
bool operator<(const SourcePositionTuple &other) const