Skip to content

Instantly share code, notes, and snippets.

@kidlab
Forked from wallace/Debugging Ruby Notes.html
Created December 6, 2015 03:50
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 kidlab/7a835e305a2ba2ec660e to your computer and use it in GitHub Desktop.
Save kidlab/7a835e305a2ba2ec660e to your computer and use it in GitHub Desktop.
My notes from Aman Gupta's Debugging Ruby webinar by Engine Yard
<a href="http://en.wikipedia.org/wiki/Lsof">lsof</a>
----
show open files
lsof -nPp <pid>
<a href="http://linux.die.net/man/1/strace">strace</a>
------
strace -cp <pid> -- summary mode, run it for a while and then hit ^C
OR
strace -ttTp <pid> -o <file> -- system call and arguments as they are happening
ruby 1.8 uses signals to schedule its green threads. process receives a SIGVTALRM signal every 10ms
in summary mode, you see a lot of calls sigprocmask (ruby bug, shows up in
linux distribution ruby because compiled w/pthread as it is spawning thread to do signaling)
<a href="http://www.tcpdump.org">tcpdump</a>
-------
tcpdump -i eth0 -s <len> -nqA <expr>
tcpdump -w <file> -- dumps to file, and then open file in wireshark for further analysis
<a href="http://code.google.com/p/google-perftools/">PERFTOOLS, google's performance tools</a>
-------------------------------------
download and compile, setup, profile and report
pprof ruby ruby.prof --text or --gif
gem install perftools.rb (only interested in ruby c calls)
-- real time (wall time) vs. CPU time
perftools does a good job helping you understand a code base as you can see the function call graph
also has object allocation profile
<a href="http://linux.die.net/man/1/ltrace">ltrace</a>
------
ltrace -cp <pid>
ltrace -ttTp <pid> -o <file>
traces library calls as opposed to strace does system calls.
joe domato - new maintainer of ltrace
no good ltrace on os x. no good strace on mac os x. dtrace works on mac os x
but doesn't replicate all the functionality of strace and ltrace
<a href="http://www.gnu.org/software/gdb/">gdb</a>
---
gdb <executable>
gdb attach <pid>
1. Attach to a running process
2. Use a coredump
gdb.rb -- gdb with MRI hooks
gem install gdb.rb
gdb.rb <pid> (does not work w/1.9 or OS X) gdb 7 not compatible on OS X
<a href="https://github.com/ice799/memprof">memprof</a> -- a heap visualizer for ruby
-------
gem install memprof
memprof.track
like bleak_house, but for a given block of code
use memprof::Middleware in your webapps to run track per request
memprof.dump
shows you details about objects created during that block. json output
memprof.dump_all
dump out every single live object as json
one per line to specified file
couple hundred mb file
analyze via
jsawk/grep
custom ruby scripts
mongodb
...
memprof.com -- fantastic!!
a web-based heap visualizer and leak analyzer
<a href="https://github.com/bhb/rack-perftools_profiler">rack-perftools</a> -- rack middleware for perftools.rb
--------------
gem install rack-perftools_profiler
middleware that adds urls to app that, if special params are included,
intercepts a request and returns profile info!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment