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
Tweet

More Decks by Dirk Breuer

Other Decks in Programming

Transcript

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

    g e h s e b 1 .0 .2 1
  2. I B

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

    "interactive cologne meets ponies".upcase => "INTERACTIVE COLOGNE MEETS PONIES" >>
  4. ~ $ 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 ~ $
  5. p t

  6. 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
  7. 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
  8. ~ $ 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)
  9. 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
  10. “B t e e r r p g f r

    R i s a d o h r R c a p ”
  11. “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
  12. 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
  13. 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); }
  14. ~ $ 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
  15. 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
  16. 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
  17. 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
  18. T a k ! Q & A? Dirk Breuer /

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