This presentation is devoted to debugging Ruby programs. At the beginning we discussed common tools like lsof, strace, etc.; in the second half - tools from the Ruby world (stackprof, ObjectSpace, byebug, etc.).
is listening for connections on a given range of ports ‣ figure out who is holding up the port ‣ figure out who is writing to the file What is lsof good for?
= -1 ENOENT (No such file or directory) <0.000264> open("<path-to-ruby>/gems/undev-0.2.2/lib/sfk/bootstrap/views/pages.rb", O_RDONLY) = -1 ENOENT (No such file or directory) <0.000144> ... 13 attempts to open a nonexistent file ... open("<path-to-ruby>/gems/sfk-bootstrap-3.0.0/lib/sfk/bootstrap/views/pages.rb", O_RDONLY) = 21 <0.0
(gdb) ruby_eval "self.pry" => [1] pry(main)> ls self.methods: inspect to_s locals: _ __ _dir_ _ex_ _file_ _in_ _out_ _pry_ title program must be compiled with pry
and SIGALRM) ‣ cpu (using ITIMER_PROF and SIGPROF) [default mode] ‣ object (using RUBY_INTERNAL_EVENT_NEWOBJ) ‣ custom (user-defined via StackProf.sample) Four sampling modes
show what kind of objects are leaking counts = Hash.new{ 0 } ObjectSpace.each_object do |o| counts[o.class] += 1 end # returns an array of objects that reference the object ObjectSpace.find_references( ObjectSpace.each_object(MainController).first ) requires patched ruby
10] in /home/davidr/Proyectos/byebug/old_doc/triangle.rb 1: # Compute the n'th triangle number: triangle(n) == (n*(n+1))/2 => 2: def triangle(n) 3: tri = 0 4: 0.upto(n) do |i| 5: tri += i 6: end 7: tri 8: end 9: 10: t = triangle(3) (byebug)