An interesting improvement would be allow at least 1 frame from Ruby land when possible. It could make it way easier to isolate Ruby leaks cause the backtrace would be richer allowing for the place in Ruby that caused a bug. Clearly this seems somewhat optional but in the cases where we have it, it could be quite amazing. Not sure if we need the entire backtrace cause that could be a bit expensive to grab. https://80x24.org/mwrap.git https://80x24.org/mwrap.git/tree/ext/mwrap/mwrap.c#n209 https://80x24.org/mwrap.git/tree/ext/mwrap/mwrap.c#n426
I'm all for finding a way to inject frames from scripting languages in some way, but so far I haven't gotten there. It will require some kind of API that would then be called by ruby. Or do you have something else in mind?
Yeah I think usability wise the best thing would be: ``` gem install heaptrack_ruby # in the ruby script require 'heaptrack_ruby' ``` Then heaptrack can publish some sort of library to register callbacks for scripting languages, and the ruby gem can then on require simply register the "lookup frame function" in the heaptrack library. Then you would use libunwind to get your stack followed by calling the callback which is injected via ruby. The actual code the Ruby extension would call to get the frame is along the lines of: ``` if (ruby_thread_has_gvl_p() && ruby_current_vm_ptr && ruby_current_execution_context_ptr) { int line; const char *ptr = rb_source_location_cstr(&line); } ``` So I guess the signature of the method would be something like this if my C is write which it is likely not: ``` heaptrack_register_backtrace_lookup( *(char**)(void) ) ```