GeezerVison is showing github.com — deps: V8: backport 20 CPU profiler commits from upstream · nodejs/node@48f31bd
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: deps/v8/include/v8-profiler.h +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -273,6 +273,16 @@ class V8_EXPORT CpuProfile { | 273 | 273 | void Delete(); | 274 | 274 | }; | 275 | 275 |
| | 276 | +enum CpuProfilingMode { | | 277 | + // In the resulting CpuProfile tree, intermediate nodes in a stack trace | | 278 | + // (from the root to a leaf) will have line numbers that point to the start | | 279 | + // line of the function, rather than the line of the callsite of the child. | | 280 | + kLeafNodeLineNumbers, | | 281 | + // In the resulting CpuProfile tree, nodes are separated based on the line | | 282 | + // number of their callsite in their parent. | | 283 | + kCallerLineNumbers, | | 284 | +}; | | 285 | + | 276 | 286 | /** | 277 | 287 | * Interface for controlling CPU profiling. Instance of the | 278 | 288 | * profiler can be created using v8::CpuProfiler::New method. | @@ -309,6 +319,13 @@ class V8_EXPORT CpuProfiler { | 309 | 319 | * |record_samples| parameter controls whether individual samples should | 310 | 320 | * be recorded in addition to the aggregated tree. | 311 | 321 | */ | | 322 | + void StartProfiling(Local<String> title, CpuProfilingMode mode, | | 323 | + bool record_samples = false); | | 324 | + /** | | 325 | + * The same as StartProfiling above, but the CpuProfilingMode defaults to | | 326 | + * kLeafNodeLineNumbers mode, which was the previous default behavior of the | | 327 | + * profiler. | | 328 | + */ | 312 | 329 | void StartProfiling(Local<String> title, bool record_samples = false); | 313 | 330 |
| 314 | 331 | /** | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/include/v8-version.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | #define V8_MAJOR_VERSION 6 | 12 | 12 | #define V8_MINOR_VERSION 2 | 13 | 13 | #define V8_BUILD_NUMBER 414 | 14 | | -#define V8_PATCH_LEVEL 67 | | 14 | +#define V8_PATCH_LEVEL 68 | 15 | 15 |
| 16 | 16 | // Use 1 for candidates and 0 otherwise. | 17 | 17 | // (Boolean macro values are not supported by all preprocessors.) | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/api.cc +9-12Lines changed: 9 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8418,7 +8418,7 @@ HeapProfiler* Isolate::GetHeapProfiler() { | 8418 | 8418 |
| 8419 | 8419 | CpuProfiler* Isolate::GetCpuProfiler() { | 8420 | 8420 | i::CpuProfiler* cpu_profiler = | 8421 | | - reinterpret_cast<i::Isolate*>(this)->cpu_profiler(); | | 8421 | + reinterpret_cast<i::Isolate*>(this)->EnsureCpuProfiler(); | 8422 | 8422 | return reinterpret_cast<CpuProfiler*>(cpu_profiler); | 8423 | 8423 | } | 8424 | 8424 |
| @@ -10138,15 +10138,7 @@ Local<String> CpuProfileNode::GetFunctionName() const { | 10138 | 10138 | const i::CodeEntry* entry = node->entry(); | 10139 | 10139 | i::Handle<i::String> name = | 10140 | 10140 | isolate->factory()->InternalizeUtf8String(entry->name()); | 10141 | | - if (!entry->has_name_prefix()) { | 10142 | | - return ToApiHandle<String>(name); | 10143 | | - } else { | 10144 | | - // We do not expect this to fail. Change this if it does. | 10145 | | - i::Handle<i::String> cons = isolate->factory()->NewConsString( | 10146 | | - isolate->factory()->InternalizeUtf8String(entry->name_prefix()), | 10147 | | - name).ToHandleChecked(); | 10148 | | - return ToApiHandle<String>(cons); | 10149 | | - } | | 10141 | + return ToApiHandle<String>(name); | 10150 | 10142 | } | 10151 | 10143 |
| 10152 | 10144 | int debug::Coverage::BlockData::StartOffset() const { return block_->start; } | @@ -10237,7 +10229,7 @@ const char* CpuProfileNode::GetScriptResourceNameStr() const { | 10237 | 10229 | } | 10238 | 10230 |
| 10239 | 10231 | int CpuProfileNode::GetLineNumber() const { | 10240 | | - return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number(); | | 10232 | + return reinterpret_cast<const i::ProfileNode*>(this)->line_number(); | 10241 | 10233 | } | 10242 | 10234 |
| 10243 | 10235 |
| @@ -10370,9 +10362,14 @@ void CpuProfiler::CollectSample() { | 10370 | 10362 |
| 10371 | 10363 | void CpuProfiler::StartProfiling(Local<String> title, bool record_samples) { | 10372 | 10364 | reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling( | 10373 | | - *Utils::OpenHandle(*title), record_samples); | | 10365 | + *Utils::OpenHandle(*title), record_samples, kLeafNodeLineNumbers); | 10374 | 10366 | } | 10375 | 10367 |
| | 10368 | +void CpuProfiler::StartProfiling(Local<String> title, CpuProfilingMode mode, | | 10369 | + bool record_samples) { | | 10370 | + reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling( | | 10371 | + *Utils::OpenHandle(*title), record_samples, mode); | | 10372 | +} | 10376 | 10373 |
| 10377 | 10374 | CpuProfile* CpuProfiler::StopProfiling(Local<String> title) { | 10378 | 10375 | return reinterpret_cast<CpuProfile*>( | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/code-events.h +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,7 +101,7 @@ class CodeEventListener { | 101 | 101 | virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0; | 102 | 102 | virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0; | 103 | 103 | virtual void RegExpCodeCreateEvent(AbstractCode* code, String* source) = 0; | 104 | | - virtual void CodeMoveEvent(AbstractCode* from, Address to) = 0; | | 104 | + virtual void CodeMoveEvent(AbstractCode* from, AbstractCode* to) = 0; | 105 | 105 | virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0; | 106 | 106 | virtual void CodeMovingGCEvent() = 0; | 107 | 107 | virtual void CodeDisableOptEvent(AbstractCode* code, | @@ -163,7 +163,7 @@ class CodeEventDispatcher { | 163 | 163 | void RegExpCodeCreateEvent(AbstractCode* code, String* source) { | 164 | 164 | CODE_EVENT_DISPATCH(RegExpCodeCreateEvent(code, source)); | 165 | 165 | } | 166 | | - void CodeMoveEvent(AbstractCode* from, Address to) { | | 166 | + void CodeMoveEvent(AbstractCode* from, AbstractCode* to) { | 167 | 167 | CODE_EVENT_DISPATCH(CodeMoveEvent(from, to)); | 168 | 168 | } | 169 | 169 | void SharedFunctionInfoMoveEvent(Address from, Address to) { | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/compilation-info.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,7 +51,7 @@ CompilationInfo::CompilationInfo(Zone* zone, Isolate* isolate, | 51 | 51 | // Collect source positions for optimized code when profiling or if debugger | 52 | 52 | // is active, to be able to get more precise source positions at the price of | 53 | 53 | // more memory consumption. | 54 | | - if (isolate_->NeedsSourcePositionsForProfiling()) { | | 54 | + if (isolate_->NeedsDetailedOptimizedCodeLineInfo()) { | 55 | 55 | MarkAsSourcePositionsEnabled(); | 56 | 56 | } | 57 | 57 | } | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/flag-definitions.h +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1082,6 +1082,9 @@ DEFINE_BOOL(log_source_code, false, "Log source code.") | 1082 | 1082 | DEFINE_BOOL(prof, false, | 1083 | 1083 | "Log statistical profiling information (implies --log-code).") | 1084 | 1084 |
| | 1085 | +DEFINE_BOOL(detailed_line_info, true, | | 1086 | + "Always generate detailed line information for CPU profiling.") | | 1087 | + | 1085 | 1088 | #if defined(ANDROID) | 1086 | 1089 | // Phones and tablets have processors that are much slower than desktop | 1087 | 1090 | // and laptop computers for which current heuristics are tuned. | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/heap/mark-compact.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1484,7 +1484,7 @@ class ProfilingMigrationObserver final : public MigrationObserver { | 1484 | 1484 | int size) final { | 1485 | 1485 | if (dest == CODE_SPACE || (dest == OLD_SPACE && dst->IsBytecodeArray())) { | 1486 | 1486 | PROFILE(heap_->isolate(), | 1487 | | - CodeMoveEvent(AbstractCode::cast(src), dst->address())); | | 1487 | + CodeMoveEvent(AbstractCode::cast(src), AbstractCode::cast(dst))); | 1488 | 1488 | } | 1489 | 1489 | heap_->OnMoveEvent(dst, src, size); | 1490 | 1490 | } | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/isolate.cc +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2697,7 +2697,6 @@ bool Isolate::Init(StartupDeserializer* des) { | 2697 | 2697 | call_descriptor_data_ = | 2698 | 2698 | new CallInterfaceDescriptorData[CallDescriptors::NUMBER_OF_DESCRIPTORS]; | 2699 | 2699 | access_compiler_data_ = new AccessCompilerData(); | 2700 | | - cpu_profiler_ = new CpuProfiler(this); | 2701 | 2700 | heap_profiler_ = new HeapProfiler(heap()); | 2702 | 2701 | interpreter_ = new interpreter::Interpreter(this); | 2703 | 2702 | compiler_dispatcher_ = | @@ -2970,6 +2969,10 @@ bool Isolate::use_optimizer() { | 2970 | 2969 | !is_precise_count_code_coverage() && !is_block_count_code_coverage(); | 2971 | 2970 | } | 2972 | 2971 |
| | 2972 | +bool Isolate::NeedsDetailedOptimizedCodeLineInfo() const { | | 2973 | + return NeedsSourcePositionsForProfiling() || FLAG_detailed_line_info; | | 2974 | +} | | 2975 | + | 2973 | 2976 | bool Isolate::NeedsSourcePositionsForProfiling() const { | 2974 | 2977 | return FLAG_trace_deopt || FLAG_trace_turbo || FLAG_trace_turbo_graph || | 2975 | 2978 | FLAG_turbo_profiling || FLAG_perf_prof || is_profiling() || | @@ -3694,6 +3697,13 @@ void Isolate::PrintWithTimestamp(const char* format, ...) { | 3694 | 3697 | va_end(arguments); | 3695 | 3698 | } | 3696 | 3699 |
| | 3700 | +CpuProfiler* Isolate::EnsureCpuProfiler() { | | 3701 | + if (!cpu_profiler_) { | | 3702 | + cpu_profiler_ = new CpuProfiler(this); | | 3703 | + } | | 3704 | + return cpu_profiler_; | | 3705 | +} | | 3706 | + | 3697 | 3707 | bool StackLimitCheck::JsHasOverflowed(uintptr_t gap) const { | 3698 | 3708 | StackGuard* stack_guard = isolate_->stack_guard(); | 3699 | 3709 | #ifdef USE_SIMULATOR | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/isolate.h +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1019,6 +1019,8 @@ class Isolate { | 1019 | 1019 |
| 1020 | 1020 | bool NeedsSourcePositionsForProfiling() const; | 1021 | 1021 |
| | 1022 | + bool NeedsDetailedOptimizedCodeLineInfo() const; | | 1023 | + | 1022 | 1024 | bool is_best_effort_code_coverage() const { | 1023 | 1025 | return code_coverage_mode() == debug::Coverage::kBestEffort; | 1024 | 1026 | } | @@ -1449,7 +1451,7 @@ class Isolate { | 1449 | 1451 |
| 1450 | 1452 | // TODO(alph): Remove along with the deprecated GetCpuProfiler(). | 1451 | 1453 | friend v8::CpuProfiler* v8::Isolate::GetCpuProfiler(); | 1452 | | - CpuProfiler* cpu_profiler() const { return cpu_profiler_; } | | 1454 | + CpuProfiler* EnsureCpuProfiler(); | 1453 | 1455 |
| 1454 | 1456 | base::Atomic32 id_; | 1455 | 1457 | EntryStackItem* entry_stack_; | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/log.cc +11-37Lines changed: 11 additions & 37 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | #include "src/log-utils.h" | 23 | 23 | #include "src/macro-assembler.h" | 24 | 24 | #include "src/perf-jit.h" | 25 | | -#include "src/profiler/profiler-listener.h" | 26 | 25 | #include "src/profiler/tick-sample.h" | 27 | 26 | #include "src/runtime-profiler.h" | 28 | 27 | #include "src/source-position-table.h" | @@ -218,7 +217,7 @@ class PerfBasicLogger : public CodeEventLogger { | 218 | 217 | PerfBasicLogger(); | 219 | 218 | ~PerfBasicLogger() override; | 220 | 219 |
| 221 | | - void CodeMoveEvent(AbstractCode* from, Address to) override {} | | 220 | + void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override {} | 222 | 221 | void CodeDisableOptEvent(AbstractCode* code, | 223 | 222 | SharedFunctionInfo* shared) override {} | 224 | 223 |
| @@ -287,7 +286,7 @@ class LowLevelLogger : public CodeEventLogger { | 287 | 286 | explicit LowLevelLogger(const char* file_name); | 288 | 287 | ~LowLevelLogger() override; | 289 | 288 |
| 290 | | - void CodeMoveEvent(AbstractCode* from, Address to) override; | | 289 | + void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override; | 291 | 290 | void CodeDisableOptEvent(AbstractCode* code, | 292 | 291 | SharedFunctionInfo* shared) override {} | 293 | 292 | void SnapshotPositionEvent(HeapObject* obj, int pos); | @@ -393,11 +392,10 @@ void LowLevelLogger::LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo*, | 393 | 392 | code->instruction_size()); | 394 | 393 | } | 395 | 394 |
| 396 | | -void LowLevelLogger::CodeMoveEvent(AbstractCode* from, Address to) { | | 395 | +void LowLevelLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) { | 397 | 396 | CodeMoveStruct event; | 398 | 397 | event.from_address = from->instruction_start(); | 399 | | - size_t header_size = from->instruction_start() - from->address(); | 400 | | - event.to_address = to + header_size; | | 398 | + event.to_address = to->instruction_start(); | 401 | 399 | LogWriteStruct(event); | 402 | 400 | } | 403 | 401 |
| @@ -419,7 +417,7 @@ class JitLogger : public CodeEventLogger { | 419 | 417 | public: | 420 | 418 | explicit JitLogger(JitCodeEventHandler code_event_handler); | 421 | 419 |
| 422 | | - void CodeMoveEvent(AbstractCode* from, Address to) override; | | 420 | + void CodeMoveEvent(AbstractCode* from, AbstractCode* to) override; | 423 | 421 | void CodeDisableOptEvent(AbstractCode* code, | 424 | 422 | SharedFunctionInfo* shared) override {} | 425 | 423 | void AddCodeLinePosInfoEvent(void* jit_handler_data, int pc_offset, | @@ -460,19 +458,14 @@ void JitLogger::LogRecordedBuffer(AbstractCode* code, | 460 | 458 | code_event_handler_(&event); | 461 | 459 | } | 462 | 460 |
| 463 | | -void JitLogger::CodeMoveEvent(AbstractCode* from, Address to) { | | 461 | +void JitLogger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) { | 464 | 462 | base::LockGuard<base::Mutex> guard(&logger_mutex_); | 465 | 463 |
| 466 | 464 | JitCodeEvent event; | 467 | 465 | event.type = JitCodeEvent::CODE_MOVED; | 468 | | - event.code_start = from->instruction_start(); | | 466 | + event.code_start = reinterpret_cast<void*>(from->instruction_start()); | 469 | 467 | event.code_len = from->instruction_size(); | 470 | | - | 471 | | - // Calculate the header size. | 472 | | - const size_t header_size = from->instruction_start() - from->address(); | 473 | | - | 474 | | - // Calculate the new start address of the instructions. | 475 | | - event.new_code_start = to + header_size; | | 468 | + event.new_code_start = reinterpret_cast<void*>(to->instruction_start()); | 476 | 469 |
| 477 | 470 | code_event_handler_(&event); | 478 | 471 | } | @@ -739,7 +732,6 @@ Logger::Logger(Isolate* isolate) | 739 | 732 | perf_jit_logger_(NULL), | 740 | 733 | ll_logger_(NULL), | 741 | 734 | jit_logger_(NULL), | 742 | | - listeners_(5), | 743 | 735 | is_initialized_(false) {} | 744 | 736 |
| 745 | 737 | Logger::~Logger() { | @@ -1297,9 +1289,10 @@ void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) { | 1297 | 1289 | msg.WriteToLogFile(); | 1298 | 1290 | } | 1299 | 1291 |
| 1300 | | -void Logger::CodeMoveEvent(AbstractCode* from, Address to) { | | 1292 | +void Logger::CodeMoveEvent(AbstractCode* from, AbstractCode* to) { | 1301 | 1293 | if (!is_logging_code_events()) return; | 1302 | | - MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), to); | | 1294 | + MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), | | 1295 | + to->address()); | 1303 | 1296 | } | 1304 | 1297 |
| 1305 | 1298 | void Logger::CodeLinePosInfoRecordEvent(AbstractCode* code, | @@ -1876,8 +1869,6 @@ bool Logger::SetUp(Isolate* isolate) { | 1876 | 1869 | profiler_->Engage(); | 1877 | 1870 | } | 1878 | 1871 |
| 1879 | | - profiler_listener_.reset(); | 1880 | | - | 1881 | 1872 | if (is_logging_) { | 1882 | 1873 | addCodeEventListener(this); | 1883 | 1874 | } | @@ -1905,19 +1896,6 @@ void Logger::SetCodeEventHandler(uint32_t options, | 1905 | 1896 | } | 1906 | 1897 | } | 1907 | 1898 |
| 1908 | | -void Logger::SetUpProfilerListener() { | 1909 | | - if (!is_initialized_) return; | 1910 | | - if (profiler_listener_.get() == nullptr) { | 1911 | | - profiler_listener_.reset(new ProfilerListener(isolate_)); | 1912 | | - } | 1913 | | - addCodeEventListener(profiler_listener_.get()); | 1914 | | -} | 1915 | | - | 1916 | | -void Logger::TearDownProfilerListener() { | 1917 | | - if (profiler_listener_->HasObservers()) return; | 1918 | | - removeCodeEventListener(profiler_listener_.get()); | 1919 | | -} | 1920 | | - | 1921 | 1899 | sampler::Sampler* Logger::sampler() { | 1922 | 1900 | return ticker_; | 1923 | 1901 | } | @@ -1961,10 +1939,6 @@ FILE* Logger::TearDown() { | 1961 | 1939 | jit_logger_ = NULL; | 1962 | 1940 | } | 1963 | 1941 |
| 1964 | | - if (profiler_listener_.get() != nullptr) { | 1965 | | - removeCodeEventListener(profiler_listener_.get()); | 1966 | | - } | 1967 | | - | 1968 | 1942 | return log_->Close(); | 1969 | 1943 | } | 1970 | 1944 |
| |
|