Skip to content

Commit

Permalink
deps: backport 4 CPU profiler commits from upstream V8
Browse files Browse the repository at this point in the history
[cpu-profiler] Add a new profiling mode with a more detailed call tree.
https://chromium.googlesource.com/v8/v8.git/+/ecae80cdb350dde1e654c531b56f5b6c44dc8c77

[cpu-profiler] Reuse free slots in code_entries_
https://chromium.googlesource.com/v8/v8.git/+/3e1126bf15e62c433c4e9cb21316d182f691c63a

[cpu-profiler] Only store deopt inline frames for functions that need it
https://chromium.googlesource.com/v8/v8.git/+/0bfcbdd4726920755e51dab28c18ab93e050819b

[cpu-profiler] Use instruction start as the key for the CodeMap
https://chromium.googlesource.com/v8/v8.git/+/ba752ea4c50713dff1e94f45a79db3ba968a8d66

PR-URL: #22028
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Benedikt Meurer <[email protected]>
  • Loading branch information
psmarshall authored and targos committed Sep 5, 2018
1 parent 7a70dce commit a5c0bc4
Show file tree
Hide file tree
Showing 21 changed files with 469 additions and 204 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.22',
'v8_embedder_string': '-node.23',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
17 changes: 17 additions & 0 deletions deps/v8/include/v8-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ class V8_EXPORT CpuProfile {
void Delete();
};

enum CpuProfilingMode {
// In the resulting CpuProfile tree, intermediate nodes in a stack trace
// (from the root to a leaf) will have line numbers that point to the start
// line of the function, rather than the line of the callsite of the child.
kLeafNodeLineNumbers,
// In the resulting CpuProfile tree, nodes are separated based on the line
// number of their callsite in their parent.
kCallerLineNumbers,
};

/**
* Interface for controlling CPU profiling. Instance of the
* profiler can be created using v8::CpuProfiler::New method.
Expand Down Expand Up @@ -316,6 +326,13 @@ class V8_EXPORT CpuProfiler {
* |record_samples| parameter controls whether individual samples should
* be recorded in addition to the aggregated tree.
*/
void StartProfiling(Local<String> title, CpuProfilingMode mode,
bool record_samples = false);
/**
* The same as StartProfiling above, but the CpuProfilingMode defaults to
* kLeafNodeLineNumbers mode, which was the previous default behavior of the
* profiler.
*/
void StartProfiling(Local<String> title, bool record_samples = false);

/**
Expand Down
9 changes: 7 additions & 2 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10005,7 +10005,7 @@ const char* CpuProfileNode::GetScriptResourceNameStr() const {
}

int CpuProfileNode::GetLineNumber() const {
return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number();
return reinterpret_cast<const i::ProfileNode*>(this)->line_number();
}


Expand Down Expand Up @@ -10143,9 +10143,14 @@ void CpuProfiler::CollectSample() {

void CpuProfiler::StartProfiling(Local<String> title, bool record_samples) {
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
*Utils::OpenHandle(*title), record_samples);
*Utils::OpenHandle(*title), record_samples, kLeafNodeLineNumbers);
}

void CpuProfiler::StartProfiling(Local<String> title, CpuProfilingMode mode,
bool record_samples) {
reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
*Utils::OpenHandle(*title), record_samples, mode);
}

CpuProfile* CpuProfiler::StopProfiling(Local<String> title) {
return reinterpret_cast<CpuProfile*>(
Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/code-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CodeEventListener {
virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0;
virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0;
virtual void RegExpCodeCreateEvent(AbstractCode* code, String* source) = 0;
virtual void CodeMoveEvent(AbstractCode* from, Address to) = 0;
virtual void CodeMoveEvent(AbstractCode* from, AbstractCode* to) = 0;
virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
virtual void CodeMovingGCEvent() = 0;
virtual void CodeDisableOptEvent(AbstractCode* code,
Expand Down Expand Up @@ -155,7 +155,7 @@ class CodeEventDispatcher {
void RegExpCodeCreateEvent(AbstractCode* code, String* source) {
CODE_EVENT_DISPATCH(RegExpCodeCreateEvent(code, source));
}
void CodeMoveEvent(AbstractCode* from, Address to) {
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
CODE_EVENT_DISPATCH(CodeMoveEvent(from, to));
}
void SharedFunctionInfoMoveEvent(Address from, Address to) {
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/heap/mark-compact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ class ProfilingMigrationObserver final : public MigrationObserver {
int size) final {
if (dest == CODE_SPACE || (dest == OLD_SPACE && dst->IsBytecodeArray())) {
PROFILE(heap_->isolate(),
CodeMoveEvent(AbstractCode::cast(src), dst->address()));
CodeMoveEvent(AbstractCode::cast(src), AbstractCode::cast(dst)));
}
heap_->OnMoveEvent(dst, src, size);
}
Expand Down
25 changes: 10 additions & 15 deletions deps/v8/src/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class PerfBasicLogger : public CodeEventLogger {
PerfBasicLogger();
~PerfBasicLogger() override;

void CodeMoveEvent(AbstractCode* from, Address to) override {}
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override {}
void CodeDisableOptEvent(AbstractCode* code,
SharedFunctionInfo* shared) override {}

Expand Down Expand Up @@ -492,7 +492,7 @@ class LowLevelLogger : public CodeEventLogger {
explicit LowLevelLogger(const char* file_name);
~LowLevelLogger() override;

void CodeMoveEvent(AbstractCode* from, Address to) override;
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
void CodeDisableOptEvent(AbstractCode* code,
SharedFunctionInfo* shared) override {}
void SnapshotPositionEvent(HeapObject* obj, int pos);
Expand Down Expand Up @@ -610,11 +610,10 @@ void LowLevelLogger::LogRecordedBuffer(const wasm::WasmCode* code,
code->instructions().length());
}

void LowLevelLogger::CodeMoveEvent(AbstractCode* from, Address to) {
void LowLevelLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
CodeMoveStruct event;
event.from_address = from->InstructionStart();
size_t header_size = from->InstructionStart() - from->address();
event.to_address = to + header_size;
event.to_address = to->InstructionStart();
LogWriteStruct(event);
}

Expand All @@ -636,7 +635,7 @@ class JitLogger : public CodeEventLogger {
public:
explicit JitLogger(JitCodeEventHandler code_event_handler);

void CodeMoveEvent(AbstractCode* from, Address to) override;
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
void CodeDisableOptEvent(AbstractCode* code,
SharedFunctionInfo* shared) override {}
void AddCodeLinePosInfoEvent(void* jit_handler_data, int pc_offset,
Expand Down Expand Up @@ -694,7 +693,7 @@ void JitLogger::LogRecordedBuffer(const wasm::WasmCode* code, const char* name,
code_event_handler_(&event);
}

void JitLogger::CodeMoveEvent(AbstractCode* from, Address to) {
void JitLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
base::LockGuard<base::Mutex> guard(&logger_mutex_);

JitCodeEvent event;
Expand All @@ -703,12 +702,7 @@ void JitLogger::CodeMoveEvent(AbstractCode* from, Address to) {
from->IsCode() ? JitCodeEvent::JIT_CODE : JitCodeEvent::BYTE_CODE;
event.code_start = reinterpret_cast<void*>(from->InstructionStart());
event.code_len = from->InstructionSize();

// Calculate the header size.
const size_t header_size = from->InstructionStart() - from->address();

// Calculate the new start address of the instructions.
event.new_code_start = reinterpret_cast<void*>(to + header_size);
event.new_code_start = reinterpret_cast<void*>(to->InstructionStart());

code_event_handler_(&event);
}
Expand Down Expand Up @@ -1450,9 +1444,10 @@ void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) {
msg.WriteToLogFile();
}

void Logger::CodeMoveEvent(AbstractCode* from, Address to) {
void Logger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
if (!is_listening_to_code_events()) return;
MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), to);
MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(),
to->address());
}

namespace {
Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class Logger : public CodeEventListener {
// Emits a code create event for a RegExp.
void RegExpCodeCreateEvent(AbstractCode* code, String* source);
// Emits a code move event.
void CodeMoveEvent(AbstractCode* from, Address to);
void CodeMoveEvent(AbstractCode* from, AbstractCode* to);
// Emits a code line info record event.
void CodeLinePosInfoRecordEvent(Address code_start,
ByteArray* source_position_table);
Expand Down Expand Up @@ -466,7 +466,7 @@ class ExternalCodeEventListener : public CodeEventListener {
void GetterCallbackEvent(Name* name, Address entry_point) override {}
void SetterCallbackEvent(Name* name, Address entry_point) override {}
void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
void CodeMoveEvent(AbstractCode* from, Address to) override {}
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override {}
void CodeDisableOptEvent(AbstractCode* code,
SharedFunctionInfo* shared) override {}
void CodeMovingGCEvent() override {}
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/perf-jit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void PerfJitLogger::LogWriteUnwindingInfo(Code* code) {
LogWriteBytes(padding_bytes, static_cast<int>(padding_size));
}

void PerfJitLogger::CodeMoveEvent(AbstractCode* from, Address to) {
void PerfJitLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) {
// We may receive a CodeMove event if a BytecodeArray object moves. Otherwise
// code relocation is not supported.
CHECK(from->IsBytecodeArray());
Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/perf-jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PerfJitLogger : public CodeEventLogger {
PerfJitLogger();
virtual ~PerfJitLogger();

void CodeMoveEvent(AbstractCode* from, Address to) override;
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override;
void CodeDisableOptEvent(AbstractCode* code,
SharedFunctionInfo* shared) override {}

Expand Down Expand Up @@ -118,7 +118,7 @@ class PerfJitLogger : public CodeEventLogger {
// PerfJitLogger is only implemented on Linux
class PerfJitLogger : public CodeEventLogger {
public:
void CodeMoveEvent(AbstractCode* from, Address to) override {
void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override {
UNIMPLEMENTED();
}

Expand Down
16 changes: 10 additions & 6 deletions deps/v8/src/profiler/cpu-profiler-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,35 @@ namespace v8 {
namespace internal {

void CodeCreateEventRecord::UpdateCodeMap(CodeMap* code_map) {
code_map->AddCode(start, entry, size);
code_map->AddCode(instruction_start, entry, instruction_size);
}


void CodeMoveEventRecord::UpdateCodeMap(CodeMap* code_map) {
code_map->MoveCode(from, to);
code_map->MoveCode(from_instruction_start, to_instruction_start);
}


void CodeDisableOptEventRecord::UpdateCodeMap(CodeMap* code_map) {
CodeEntry* entry = code_map->FindEntry(start);
CodeEntry* entry = code_map->FindEntry(instruction_start);
if (entry != nullptr) {
entry->set_bailout_reason(bailout_reason);
}
}


void CodeDeoptEventRecord::UpdateCodeMap(CodeMap* code_map) {
CodeEntry* entry = code_map->FindEntry(start);
if (entry != nullptr) entry->set_deopt_info(deopt_reason, deopt_id);
CodeEntry* entry = code_map->FindEntry(instruction_start);
if (entry == nullptr) return;
std::vector<CpuProfileDeoptFrame> frames_vector(
deopt_frames, deopt_frames + deopt_frame_count);
entry->set_deopt_info(deopt_reason, deopt_id, std::move(frames_vector));
delete[] deopt_frames;
}


void ReportBuiltinEventRecord::UpdateCodeMap(CodeMap* code_map) {
CodeEntry* entry = code_map->FindEntry(start);
CodeEntry* entry = code_map->FindEntry(instruction_start);
if (!entry) {
// Code objects for builtins should already have been added to the map but
// some of them have been filtered out by CpuProfiler.
Expand Down
14 changes: 7 additions & 7 deletions deps/v8/src/profiler/cpu-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,20 @@ void CpuProfiler::CollectSample() {
}
}

void CpuProfiler::StartProfiling(const char* title, bool record_samples) {
if (profiles_->StartProfiling(title, record_samples)) {
void CpuProfiler::StartProfiling(const char* title, bool record_samples,
ProfilingMode mode) {
if (profiles_->StartProfiling(title, record_samples, mode)) {
TRACE_EVENT0("v8", "CpuProfiler::StartProfiling");
StartProcessorIfNotStarted();
}
}


void CpuProfiler::StartProfiling(String* title, bool record_samples) {
StartProfiling(profiles_->GetName(title), record_samples);
void CpuProfiler::StartProfiling(String* title, bool record_samples,
ProfilingMode mode) {
StartProfiling(profiles_->GetName(title), record_samples, mode);
isolate_->debug()->feature_tracker()->Track(DebugFeatureTracker::kProfiler);
}


void CpuProfiler::StartProcessorIfNotStarted() {
if (processor_) {
processor_->AddCurrentStack(isolate_);
Expand Down Expand Up @@ -426,7 +426,7 @@ void CpuProfiler::LogBuiltins() {
CodeEventsContainer evt_rec(CodeEventRecord::REPORT_BUILTIN);
ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_;
Builtins::Name id = static_cast<Builtins::Name>(i);
rec->start = builtins->builtin(id)->address();
rec->instruction_start = builtins->builtin(id)->InstructionStart();
rec->builtin_id = id;
processor_->Enqueue(evt_rec);
}
Expand Down
23 changes: 14 additions & 9 deletions deps/v8/src/profiler/cpu-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,26 @@ class CodeEventRecord {

class CodeCreateEventRecord : public CodeEventRecord {
public:
Address start;
Address instruction_start;
CodeEntry* entry;
unsigned size;
unsigned instruction_size;

INLINE(void UpdateCodeMap(CodeMap* code_map));
};


class CodeMoveEventRecord : public CodeEventRecord {
public:
Address from;
Address to;
Address from_instruction_start;
Address to_instruction_start;

INLINE(void UpdateCodeMap(CodeMap* code_map));
};


class CodeDisableOptEventRecord : public CodeEventRecord {
public:
Address start;
Address instruction_start;
const char* bailout_reason;

INLINE(void UpdateCodeMap(CodeMap* code_map));
Expand All @@ -81,19 +81,21 @@ class CodeDisableOptEventRecord : public CodeEventRecord {

class CodeDeoptEventRecord : public CodeEventRecord {
public:
Address start;
Address instruction_start;
const char* deopt_reason;
int deopt_id;
Address pc;
int fp_to_sp_delta;
CpuProfileDeoptFrame* deopt_frames;
int deopt_frame_count;

INLINE(void UpdateCodeMap(CodeMap* code_map));
};


class ReportBuiltinEventRecord : public CodeEventRecord {
public:
Address start;
Address instruction_start;
Builtins::Name builtin_id;

INLINE(void UpdateCodeMap(CodeMap* code_map));
Expand Down Expand Up @@ -197,10 +199,13 @@ class CpuProfiler : public CodeEventObserver {

static void CollectSample(Isolate* isolate);

typedef v8::CpuProfilingMode ProfilingMode;

void set_sampling_interval(base::TimeDelta value);
void CollectSample();
void StartProfiling(const char* title, bool record_samples = false);
void StartProfiling(String* title, bool record_samples);
void StartProfiling(const char* title, bool record_samples = false,
ProfilingMode mode = ProfilingMode::kLeafNodeLineNumbers);
void StartProfiling(String* title, bool record_samples, ProfilingMode mode);
CpuProfile* StopProfiling(const char* title);
CpuProfile* StopProfiling(String* title);
int GetProfilesCount();
Expand Down
3 changes: 2 additions & 1 deletion deps/v8/src/profiler/profile-generator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ inline CodeEntry* ProfileGenerator::FindEntry(Address address) {
}

ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry,
ProfileNode* parent)
ProfileNode* parent, int line_number)
: tree_(tree),
entry_(entry),
self_ticks_(0),
line_number_(line_number),
parent_(parent),
id_(tree->next_node_id()) {
tree_->EnqueueNode(this);
Expand Down
Loading

0 comments on commit a5c0bc4

Please sign in to comment.