javierhonduco / rbperf

Low-overhead sampling profiler and tracer for Ruby for Linux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a mode to run a ruby process directly

javierhonduco opened this issue · comments

Summary

This is a feature that several people have brought up. The idea would be to spawn a Ruby process directly and start profiling it. So instead of having to do this

# in one terminal or in the background
$ bundler run my_ruby_app
$ rbperf record --pid `pidof my_ruby_app` cpu

We could do

$ rbperf record --exec 'bundler run my_ruby_app' cpu

Possible implementation

This feature needs to control the execution of another process so the ptrace(2) system call is a good fit.

Something that this implementation might have to handle is the race condition between the moment when the process is executed and when all the libraries have been mapped in memory as there's a window when libruby, in the case of dynamically compiled CRuby, might not be mapped into memory yet, and we would have to fail to find the global data that rbperf needs to read

rbperf/src/process.rs

Lines 73 to 76 in 48ce25b

let ruby_version = ruby_version(&bin_path).unwrap();
debug!("Binary {:?}", bin_path);
let symbol = ruby_current_vm_address(&bin_path, &ruby_version)?;