Skip to content

Commit 0bf45a8

Browse files
RaisinTentargos
authored andcommitted
deps: V8: backport e5dbbbadcbff
Original commit message: Enable --perf-prof flag on MacOS MacOS actually can share the implementation of {PerfJitLogger} with Linux. From the issue 40112126, only Fuzzer tests on Windows ran into UNREACHABLE/FATAL because of the unimplemented {PerfJitLogger}. This CL enables the flag --perf-prof on MacOS. Bug: 403765219 Change-Id: I97871fbcc0cb9890c51ca14fd7a6e65bd0e3c0d2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6385655 Reviewed-by: Clemens Backes <clemensb@chromium.org> Reviewed-by: Matthias Liedtke <mliedtke@chromium.org> Auto-Submit: 杨文明 <yangwenming@bytedance.com> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/main@{#99885} Refs: v8/v8@e5dbbba Co-authored-by: Darshan Sen <raisinten@gmail.com> PR-URL: #60524 Refs: v8/v8@e5dbbba Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 4993bdc commit 0bf45a8

File tree

7 files changed

+81
-80
lines changed

7 files changed

+81
-80
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.32',
41+
'v8_embedder_string': '-node.33',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/src/compiler/backend/code-generator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ void CodeGenerator::AssembleCode() {
435435
}
436436
}
437437

438-
// The LinuxPerfJitLogger logs code up until here, excluding the safepoint
438+
// The PerfJitLogger logs code up until here, excluding the safepoint
439439
// table. Resolve the unwinding info now so it is aware of the same code
440440
// size as reported by perf.
441441
unwinding_info_writer_.Finish(masm()->pc_offset());

deps/v8/src/diagnostics/perf-jit.cc

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#include "src/common/assert-scope.h"
3131
#include "src/flags/flags.h"
3232

33-
// Only compile the {LinuxPerfJitLogger} on Linux.
34-
#if V8_OS_LINUX
33+
// Only compile the {PerfJitLogger} on Linux & Darwin.
34+
#if V8_OS_LINUX || V8_OS_DARWIN
3535

3636
#include <fcntl.h>
3737
#include <sys/mman.h>
@@ -118,22 +118,22 @@ struct PerfJitCodeUnwindingInfo : PerfJitBase {
118118
// Followed by size_ - sizeof(PerfJitCodeUnwindingInfo) bytes of data.
119119
};
120120

121-
const char LinuxPerfJitLogger::kFilenameFormatString[] = "%s/jit-%d.dump";
121+
const char PerfJitLogger::kFilenameFormatString[] = "%s/jit-%d.dump";
122122

123123
// Extra padding for the PID in the filename
124-
const int LinuxPerfJitLogger::kFilenameBufferPadding = 16;
124+
const int PerfJitLogger::kFilenameBufferPadding = 16;
125125

126126
static const char kStringTerminator[] = {'\0'};
127127

128128
// The following static variables are protected by
129129
// GetFileMutex().
130-
int LinuxPerfJitLogger::process_id_ = 0;
131-
uint64_t LinuxPerfJitLogger::reference_count_ = 0;
132-
void* LinuxPerfJitLogger::marker_address_ = nullptr;
133-
uint64_t LinuxPerfJitLogger::code_index_ = 0;
134-
FILE* LinuxPerfJitLogger::perf_output_handle_ = nullptr;
130+
int PerfJitLogger::process_id_ = 0;
131+
uint64_t PerfJitLogger::reference_count_ = 0;
132+
void* PerfJitLogger::marker_address_ = nullptr;
133+
uint64_t PerfJitLogger::code_index_ = 0;
134+
FILE* PerfJitLogger::perf_output_handle_ = nullptr;
135135

136-
void LinuxPerfJitLogger::OpenJitDumpFile() {
136+
void PerfJitLogger::OpenJitDumpFile() {
137137
// Open the perf JIT dump file.
138138
perf_output_handle_ = nullptr;
139139

@@ -153,22 +153,31 @@ void LinuxPerfJitLogger::OpenJitDumpFile() {
153153
if (v8_flags.perf_prof_delete_file)
154154
CHECK_EQ(0, unlink(perf_dump_name.begin()));
155155

156+
// On Linux, call OpenMarkerFile so that perf knows about the file path via
157+
// an MMAP record.
158+
// On macOS, don't call OpenMarkerFile because samply has already detected
159+
// the file path during the call to `open` above (it interposes `open` with
160+
// a preloaded library), and because the mmap call can be slow.
161+
#if V8_OS_DARWIN
162+
marker_address_ = nullptr;
163+
#else
156164
marker_address_ = OpenMarkerFile(fd);
157165
if (marker_address_ == nullptr) return;
166+
#endif
158167

159168
perf_output_handle_ = fdopen(fd, "w+");
160169
if (perf_output_handle_ == nullptr) return;
161170

162171
setvbuf(perf_output_handle_, nullptr, _IOFBF, kLogBufferSize);
163172
}
164173

165-
void LinuxPerfJitLogger::CloseJitDumpFile() {
174+
void PerfJitLogger::CloseJitDumpFile() {
166175
if (perf_output_handle_ == nullptr) return;
167176
base::Fclose(perf_output_handle_);
168177
perf_output_handle_ = nullptr;
169178
}
170179

171-
void* LinuxPerfJitLogger::OpenMarkerFile(int fd) {
180+
void* PerfJitLogger::OpenMarkerFile(int fd) {
172181
long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int)
173182
if (page_size == -1) return nullptr;
174183

@@ -180,15 +189,14 @@ void* LinuxPerfJitLogger::OpenMarkerFile(int fd) {
180189
return (marker_address == MAP_FAILED) ? nullptr : marker_address;
181190
}
182191

183-
void LinuxPerfJitLogger::CloseMarkerFile(void* marker_address) {
192+
void PerfJitLogger::CloseMarkerFile(void* marker_address) {
184193
if (marker_address == nullptr) return;
185194
long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int)
186195
if (page_size == -1) return;
187196
munmap(marker_address, page_size);
188197
}
189198

190-
LinuxPerfJitLogger::LinuxPerfJitLogger(Isolate* isolate)
191-
: CodeEventLogger(isolate) {
199+
PerfJitLogger::PerfJitLogger(Isolate* isolate) : CodeEventLogger(isolate) {
192200
base::LockGuard<base::RecursiveMutex> guard_file(GetFileMutex().Pointer());
193201
process_id_ = base::OS::GetCurrentProcessId();
194202

@@ -201,7 +209,7 @@ LinuxPerfJitLogger::LinuxPerfJitLogger(Isolate* isolate)
201209
}
202210
}
203211

204-
LinuxPerfJitLogger::~LinuxPerfJitLogger() {
212+
PerfJitLogger::~PerfJitLogger() {
205213
base::LockGuard<base::RecursiveMutex> guard_file(GetFileMutex().Pointer());
206214

207215
reference_count_--;
@@ -211,16 +219,11 @@ LinuxPerfJitLogger::~LinuxPerfJitLogger() {
211219
}
212220
}
213221

214-
uint64_t LinuxPerfJitLogger::GetTimestamp() {
215-
struct timespec ts;
216-
int result = clock_gettime(CLOCK_MONOTONIC, &ts);
217-
DCHECK_EQ(0, result);
218-
USE(result);
219-
static const uint64_t kNsecPerSec = 1000000000;
220-
return (ts.tv_sec * kNsecPerSec) + ts.tv_nsec;
222+
uint64_t PerfJitLogger::GetTimestamp() {
223+
return base::TimeTicks::Now().since_origin().InNanoseconds();
221224
}
222225

223-
void LinuxPerfJitLogger::LogRecordedBuffer(
226+
void PerfJitLogger::LogRecordedBuffer(
224227
Tagged<AbstractCode> abstract_code,
225228
MaybeDirectHandle<SharedFunctionInfo> maybe_sfi, const char* name,
226229
size_t length) {
@@ -264,8 +267,8 @@ void LinuxPerfJitLogger::LogRecordedBuffer(
264267
}
265268

266269
#if V8_ENABLE_WEBASSEMBLY
267-
void LinuxPerfJitLogger::LogRecordedBuffer(const wasm::WasmCode* code,
268-
const char* name, size_t length) {
270+
void PerfJitLogger::LogRecordedBuffer(const wasm::WasmCode* code,
271+
const char* name, size_t length) {
269272
base::LockGuard<base::RecursiveMutex> guard_file(GetFileMutex().Pointer());
270273

271274
if (perf_output_handle_ == nullptr) return;
@@ -277,10 +280,9 @@ void LinuxPerfJitLogger::LogRecordedBuffer(const wasm::WasmCode* code,
277280
}
278281
#endif // V8_ENABLE_WEBASSEMBLY
279282

280-
void LinuxPerfJitLogger::WriteJitCodeLoadEntry(const uint8_t* code_pointer,
281-
uint32_t code_size,
282-
const char* name,
283-
size_t name_length) {
283+
void PerfJitLogger::WriteJitCodeLoadEntry(const uint8_t* code_pointer,
284+
uint32_t code_size, const char* name,
285+
size_t name_length) {
284286
PerfJitCodeLoad code_load;
285287
code_load.event_ = PerfJitCodeLoad::kLoad;
286288
code_load.size_ =
@@ -342,8 +344,8 @@ SourcePositionInfo GetSourcePositionInfo(
342344

343345
} // namespace
344346

345-
void LinuxPerfJitLogger::LogWriteDebugInfo(
346-
Tagged<Code> code, DirectHandle<SharedFunctionInfo> shared) {
347+
void PerfJitLogger::LogWriteDebugInfo(Tagged<Code> code,
348+
DirectHandle<SharedFunctionInfo> shared) {
347349
// Line ends of all scripts have been initialized prior to this.
348350
DisallowGarbageCollection no_gc;
349351
// The WasmToJS wrapper stubs have source position entries.
@@ -425,7 +427,7 @@ void LinuxPerfJitLogger::LogWriteDebugInfo(
425427
}
426428

427429
#if V8_ENABLE_WEBASSEMBLY
428-
void LinuxPerfJitLogger::LogWriteDebugInfo(const wasm::WasmCode* code) {
430+
void PerfJitLogger::LogWriteDebugInfo(const wasm::WasmCode* code) {
429431
if (code->IsAnonymous()) {
430432
return;
431433
}
@@ -497,7 +499,7 @@ void LinuxPerfJitLogger::LogWriteDebugInfo(const wasm::WasmCode* code) {
497499
}
498500
#endif // V8_ENABLE_WEBASSEMBLY
499501

500-
void LinuxPerfJitLogger::LogWriteUnwindingInfo(Tagged<Code> code) {
502+
void PerfJitLogger::LogWriteUnwindingInfo(Tagged<Code> code) {
501503
PerfJitCodeUnwindingInfo unwinding_info_header;
502504
unwinding_info_header.event_ = PerfJitCodeLoad::kUnwindingInfo;
503505
unwinding_info_header.time_stamp_ = GetTimestamp();
@@ -532,13 +534,13 @@ void LinuxPerfJitLogger::LogWriteUnwindingInfo(Tagged<Code> code) {
532534
LogWriteBytes(padding_bytes, padding_size);
533535
}
534536

535-
void LinuxPerfJitLogger::LogWriteBytes(const char* bytes, size_t size) {
537+
void PerfJitLogger::LogWriteBytes(const char* bytes, size_t size) {
536538
size_t rv = fwrite(bytes, 1, size, perf_output_handle_);
537539
DCHECK_EQ(size, rv);
538540
USE(rv);
539541
}
540542

541-
void LinuxPerfJitLogger::LogWriteHeader() {
543+
void PerfJitLogger::LogWriteHeader() {
542544
DCHECK_NOT_NULL(perf_output_handle_);
543545
PerfJitHeader header;
544546

@@ -559,4 +561,4 @@ void LinuxPerfJitLogger::LogWriteHeader() {
559561
} // namespace internal
560562
} // namespace v8
561563

562-
#endif // V8_OS_LINUX
564+
#endif // V8_OS_LINUX || V8_OS_DARWIN

deps/v8/src/diagnostics/perf-jit.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@
3030

3131
#include "include/v8config.h"
3232

33-
// {LinuxPerfJitLogger} is only implemented on Linux.
34-
#if V8_OS_LINUX
33+
// {PerfJitLogger} is only implemented on Linux & Darwin.
34+
#if V8_OS_LINUX || V8_OS_DARWIN
3535

3636
#include "src/logging/log.h"
3737

3838
namespace v8 {
3939
namespace internal {
4040

4141
// Linux perf tool logging support.
42-
class LinuxPerfJitLogger : public CodeEventLogger {
42+
class PerfJitLogger : public CodeEventLogger {
4343
public:
44-
explicit LinuxPerfJitLogger(Isolate* isolate);
45-
~LinuxPerfJitLogger() override;
44+
explicit PerfJitLogger(Isolate* isolate);
45+
~PerfJitLogger() override;
4646

4747
void CodeMoveEvent(Tagged<InstructionStream> from,
4848
Tagged<InstructionStream> to) override {
@@ -143,6 +143,6 @@ class LinuxPerfJitLogger : public CodeEventLogger {
143143
} // namespace internal
144144
} // namespace v8
145145

146-
#endif // V8_OS_LINUX
146+
#endif // V8_OS_LINUX || V8_OS_DARWIN
147147

148148
#endif // V8_DIAGNOSTICS_PERF_JIT_H_

deps/v8/src/flags/flag-definitions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,7 +3264,7 @@ DEFINE_IMPLICATION(prof, log_code)
32643264

32653265
DEFINE_BOOL(ll_prof, false, "Enable low-level linux profiler.")
32663266

3267-
#if V8_OS_LINUX
3267+
#if V8_OS_LINUX || V8_OS_DARWIN
32683268
#define DEFINE_PERF_PROF_BOOL(nam, cmt) DEFINE_BOOL(nam, false, cmt)
32693269
#define DEFINE_PERF_PROF_IMPLICATION DEFINE_IMPLICATION
32703270
#else
@@ -3281,7 +3281,7 @@ DEFINE_BOOL(ll_prof, false, "Enable low-level linux profiler.")
32813281
#endif
32823282

32833283
DEFINE_PERF_PROF_BOOL(perf_basic_prof,
3284-
"Enable perf linux profiler (basic support).")
3284+
"Enable basic support for perf profiler.")
32853285
DEFINE_NEG_IMPLICATION(perf_basic_prof, compact_code_space)
32863286
DEFINE_STRING(perf_basic_prof_path, DEFAULT_PERF_BASIC_PROF_PATH,
32873287
"directory to write perf-<pid>.map symbol file to")
@@ -3290,8 +3290,8 @@ DEFINE_PERF_PROF_BOOL(
32903290
"Only report function code ranges to perf (i.e. no stubs).")
32913291
DEFINE_PERF_PROF_IMPLICATION(perf_basic_prof_only_functions, perf_basic_prof)
32923292

3293-
DEFINE_PERF_PROF_BOOL(
3294-
perf_prof, "Enable perf linux profiler (experimental annotate support).")
3293+
DEFINE_PERF_PROF_BOOL(perf_prof,
3294+
"Enable experimental annotate support for perf profiler.")
32953295
DEFINE_STRING(perf_prof_path, DEFAULT_PERF_PROF_PATH,
32963296
"directory to write jit-<pid>.dump symbol file to")
32973297
DEFINE_PERF_PROF_BOOL(

0 commit comments

Comments
 (0)