rbspy
rbspy copied to clipboard
Implement native profiling
resolves https://github.com/rbspy/rbspy/issues/372
How does it work?
When the native-profiling flag is on and we are on linux or windows (remoteprocess only supports unwinding on these 2 platforms afaik) then, after getting the ruby trace, we:
- get native stack frames using remoteprocess
- go through the ruby frames, when a c function is found
- find the closest start of a c function invocation in the native frames
- add all the frames from it
- stop adding when we know we are going back to ruby
The start of a c function is: rb_vm_exec and the end of it is: vm_call_cfunc_with_frame.
By interweaving native and ruby frames this way, we get to profile both ruby and native code!
Limitations
It seems like this may not work with YJIT, as it can get rid of some rb_vm_exec calls and can optimise vm_call_cfunc_with_frame