Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby is Magic: Debugging

Ruby is Magic: Debugging

In the latest installment of Ruby is Magic @tisba and I talked about some ways of debugging your code in Ruby. Like usual, the talk was in German.

Copyright Notice: My Little Pony - Friendship is Magic is Property of Hasbro and The Hub.


Dirk Breuer

June 19, 2013

More Decks by Dirk Breuer

Other Decks in Programming


  1. B o y U e G o p C l

    g e h s e b 1 .0 .2 1
  2. Ruby #014 D b g i g

  3. None
  4. F c t o D b g i g R

  5. B s c

  6. I B

  7. ~ $ irb >> 1 + 1 => 2 >>

    "interactive cologne meets ponies".upcase => "INTERACTIVE COLOGNE MEETS PONIES" >>
  8. class Discord class << self def perform_chaos targets = find(:ponies)

    play_prank_on targets end end end
  9. ~ $ irb -r ./irb_example.rb >> irb Discord >> def

    self.true_chaos; puts "\m/"; end => nil >> jobs => #0->irb on main (#<Thread:0x007fc4c30c0d98>: stop) #1->irb#1 on Discord (#<Thread:0x007fc4c4ad5ee0>: running) >> fg 0 => #<IRB::Irb> >> Discord.true_chaos \m/ => nil >> fg 1 => #<IRB::Irb> >> exit => #<IRB::Irb> >> exit ~ $
  10. p t

  11. L g e

  12. class PonyService class << self def complex_business_logic MagicLogger.info "[PonyService] STARTING

    complex_business_logic" some_data = less_complex_logic MagicLogger.debug "[PonyService] some_data=#{some_data}" more_data = another_not_so_complex_logic MagicLogger.debug "[PonyService] more_data=#{more_data}" final_data = combination_logic(some_data, more_data) MagicLogger.debug "[PonyService] final_data=#{final_data}" MagicLogger.info "[PonyService] FINISHED complex_business_logic" end end end
  13. B O O I G!!!

  14. R b D b g e

  15. gem 'ruby-debug'

  16. require 'debugger' class PinkiePie def self.twitcha_twitch puts "Something is about

    to fall!" debugger puts "(Something has fallen down on #{@somepony})" end end PinkiePie.twitcha_twitch
  17. ~ $ ruby debugger_example.rb Something is about to fall! debugger_example.rb:14

    puts "(Something has fallen down on #{@somepony})" [9, 18] in debugger_example.rb 9 end 10 11 def twitcha_twitch 12 puts "Something is about to fall!" 13 debugger => 14 puts "(Something has fallen down on #{@somepony})" 15 end 16 17 end 18 (rdb:1)
  18. ruby-debug help v1.6.0 Type 'help <command-name>' for help on a

    specific command Available commands: backtrace delete enable help list ps save start undisplay break disable eval info method putl set step up catch display exit irb next quit show thread var condition down finish jump p reload skip tmate where continue edit frame kill pp restart source trace
  19. “B t e e r r p g f r

    R i s a d o h r R c a p ”
  20. gem 'better_errors' gem 'binding_of_caller'

  21. None
  22. D r c

  23. “D r c i a c m r h n

    i e d n m c t a i g f a e o k c e t d b S n [...] f r t o b e h o i g k r e a d a p i a i n p o l m o p o u t o s s e s i r a t m .” h t ://e .w k p d a.o g/w k /D r c
  24. class Pony attr_reader :name def initialize(name) @name = name end

    def say_hello puts "#{name} says hello to Interactive Cologne!" end end twighlight = Pony.new "Twighlight Sparkle" twighlight.say_hello rainbow_dash = Pony.new "Rainbow Dash" rainbow_dash.say_hello
  25. ruby*:::object-create { /* If you look up code of rb_obj_alloc,

    first argument to * function contains class which is being instantiated */ @objects[copyinstr(arg0)] = count(); } END { /* Truncate the aggregate to top 20 results */ trunc(@objects,20); /* Print the aggregate */ printa(@objects); }
  26. ~ $ sudo dtrace -qs objects_created.d -c '/path/to/ruby dtrace_example.rb' Twighlight

    Sparkle says hello to Interactive Cologne! Rainbow Dash says hello to Interactive Cologne! #<Class:0x007fd3688e0740> 1 ARGF.class 1 IOError 1 Mutex 1 NoMemoryError 1 SystemStackError 1 ThreadGroup 1 Time 1 LoadError 2 Object 2 Pony 2 Gem::Specification 8 Gem::Version 10 Hash 11 Gem::Requirement 23 Array 96 String 260
  27. D r c L s s o h t ://c

    y t.c d m n e s.c m/p s s/2 1 -0 -1 - p o l -r b -a p -d r c -p r 2/ h t ://t n e l v m k n .c m/2 1 /1 /0 /p o l n -r i s- s a t p-w t -d r c .h m
  28. F n F c ™ R m t D b

    g i g
  29. None
  30. require 'debugger' Debugger.wait_connection = true Debugger.start_remote ... ~ $ rdebug

    -c h t ://b s d .s u c f r e.n t/r b -d b g.h m
  31. D r u y D b g e s s

    p r nüt l c ! E n a h a b n t e ! D r c e l u t l i h g w c t g s P o l n e n s l u e d n S s e s V e e T o s a n c t a g s r c e : z.B.: ruby-prof, perftools, mini- profiler
  32. O e M r T i g …

  33. None
  34. R i s a p G r a y 2013

  35. W e m J l 27/28, 2013 W e e

    m A e t u r a l n K l , C l g e h t ://2013.r i s a p.d / W o m Y u 8
  36. None
  37. T a k ! Q & A? Dirk Breuer /

    @railsbros_dirk Sebastian Cohnen / @tisba ? “My Little Pony” © Hasbro Studios and DHX Media Vancouver rubyismagic.de