Skip to content

Instantly share code, notes, and snippets.

@jrun
Created February 8, 2012 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrun/1771529 to your computer and use it in GitHub Desktop.
Save jrun/1771529 to your computer and use it in GitHub Desktop.
Using dtrace, trace method calls for a given, fully qualified module. If a module is not given all method calls are traced.
#!/usr/bin/env ruby
# This script requires the traced Ruby process to be tenderlove's probes
# branch (https://github.com/tenderlove/ruby-1/tree/probes).
fq_module = ARGV[0]
d_script = "ruby*:::function-entry\n"
d_script << "/copyinstr(arg0) == \"#{fq_module}\"/\n" if fq_module
d_script << <<-ACTION
{
printf("%s[%d] %s %s %s:%d\\n", execname, pid, copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3);
}
ACTION
exec "sudo dtrace -q -n '#{d_script}'"
@jrun
Copy link
Author

jrun commented Mar 2, 2012

The update version is kept in my dotfiles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment