How do I measure CPU cache and prefetch misses in JavaScript engines?

1.4k Views Asked by At

I want a command-line way to evaluate low-level contributors to lower performance-per-watt of Node.js applications. Namely, L1, L2, and prefetch cache misses of JIT-generated native code, as well as the JIT/GC/interpteter of the JavaScript runtime itself.

JavaScriptCore, v8, and ChakraCore all supply commandline REPLs for running benchmarks. What profiler(s) can I run on Intel-, AMD-, and ARMv6-based hardware to gather these statistics with reasonable accuracy? I'd prefer to have a way to do this across at least two operating systems: Windows, Mac, and/or Linux.

2

There are 2 best solutions below

4
On BEST ANSWER

V8 and the Linux perf tool support each other, see the documentation. If you have a very recent system (IIRC kernel >= 4.4 and perf >= 4.10), you can skip the steps for compiling your own kernel and perf.

1
On

You can use Valgrind. Quoting their FAQ, "Valgrind can handle dynamically generated code, so long as none of the generated code is later overwritten by other generated code".

It is also supported on various platforms including X86/Linux, X86/Darwin etc