Created
August 12, 2013 14:04
-
-
Save mmullis/6211061 to your computer and use it in GitHub Desktop.
Debugging and Dumping the state of a running Ruby process using GDB.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connect to ruby process | |
gdb `which ruby` <pid> | |
# Run GC | |
p rb_eval_string("GC.start") | |
# Count each Object class | |
p rb_eval_string("$gdb_objs = Hash.new 0") | |
p rb_eval_string("ObjectSpace.each_object {|o| $gdb_objs[o.class] += 1}") | |
p rb_eval_string("$stderr.puts($gdb_objs.inspect)") | |
# Show ObjectSpace.count_objects | |
p rb_eval_string("$stderr.puts(ObjectSpace.count_objects)") | |
# Print portion of every String - good if you need to find excessive duplication | |
p rb_eval_string("ObjectSpace.each_object {|v| $stderr.puts(v[0,132]) if v.is_a?(String)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment