mstange / samply

Command-line sampling profiler for macOS and Linux
Apache License 2.0
2.35k stars 58 forks source link

state of jitdump on macOS? #417

Open tmm1 opened 5 days ago

tmm1 commented 5 days ago

hi, have been using (and loving) samply for a few weeks. it's really an incredible tool, thank you.

my goal is to profile nodejs and electron processes. the former already works quite well on linux, thanks to all the work done towards jitdump support.

i also see several mentions of jitdump macos support, in the changelog and in commits like https://github.com/mstange/samply/commit/2732e49844b4b9144a742b5b6cb3d00e1cc877b2

my understanding is that jitdumps are ELF-based, but it appears that's still the standard format ingested on macos? thus, programs are expected to output jitdumps the same way on both linux and macos, along with the map files in /tmp.

in the case of nodejs, it appears the jitdump code is all gated away to be linux-specific atm: https://github.com/nodejs/node/blob/985262a4a8221d993df82e134623d8437d92b4c5/deps/v8/src/diagnostics/perf-jit.cc#L32-L33

am i correct that the first step here would be to enable this codepath inside nodejs on darwin? what else would be required.

EDIT: found https://bugzilla-dev.allizom.org/show_bug.cgi?id=1827214 so it looks like I am on the right track

tmm1 commented 5 days ago

I was able to start emitting perf-pid.map and jit-pid.dump files.

The map files are working in samply 🎉

The jitdumps are being picked by the dyld preload, and I confirmed that samply is able to parse the file to see the load/unwind sections. However, symbolization doesn't work for some reason. Any pointers?

tmm1 commented 2 days ago

the patch to v8 is quite trivial: https://github.com/tmm1/node/commit/3542e4e2944f2fe1132ded1052e223f54c90e4bf

tmm1 commented 2 days ago

samply also works on macOS with JavaScriptCore via logJITCodeForPerf. for example, using bun:

BUN_JSC_logJITCodeForPerf=1 samply record bun ...