Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Last active December 11, 2015 20:08
Show Gist options
  • Save dpaluy/4652948 to your computer and use it in GitHub Desktop.
Save dpaluy/4652948 to your computer and use it in GitHub Desktop.
Debuggin Ruby
GC.enable_stats if defined?(GC) && GC.respond_to?(:enable_stats)
GC.start # clean up heap
# dump it, including class names of heap objects
GC.dump_file_and_line_info(filename: "heap.dump", include_class_names: true)
stat_string = "allocated: #{GC.allocated_size/1024}K total in #{GC.num_allocations} allocations, GC calls: #{GC.collections}, GC time: #{GC.time / 1000} msec"
rvm get stable
find $rvm_path/patch* -type f # See all your patches
rvm install 1.9.3 --patch railsexpress -C --enable-gcdebug -n gcdebug
def get_object_stats
return_value = Hash.new
ObjectSpace::each_object(Object) {|my_object|
unless return_value[my_object.class.to_s.downcase].nil?
return_value[my_object.class.to_s.downcase][:count] += 1
else
return_value[my_object.class.to_s.downcase] = Hash.new
return_value[my_object.class.to_s.downcase][:name] = my_object.class
return_value[my_object.class.to_s.downcase][:count] = 1
end
}
return_value.sort_by {|k,v| -v[:count]}
end
@dpaluy
Copy link
Author

dpaluy commented Apr 5, 2013

Another useful patch:
rvm install 1.9.3 --with-gcc=gcc --patch gcdata -n gcdata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment