I'm using the v8 library to run JavaScript code in C++-project. And I want to log every bytecode instruction at run time. Is it possible or not? Or can I only log the assembly instructions? And if I can, then how? The trace log is required, not the result of disassembling bytecode.
If you build with the V8_TRACE_IGNITION
symbol defined (by putting v8_enable_trace_ignition = true
into your args.gn
), you can then use the flag --trace-ignition
.
Note that V8 optimizes hot functions after a while, at which point they'll no longer run in the interpreter and hence will no longer be traced. For your purposes, you can turn that off with --noopt
; of course doing so will significantly degrade performance of computationally intensive programs (10x slower wouldn't be unexpected; the exact number depends a lot on what the code is doing).
Also, please be aware that counting bytecode instructions will be a very coarse approximation of program complexity. For example, a single bytecode could call a builtin that does an arbitrarily expensive operation.