Skip to content

Instantly share code, notes, and snippets.

@akuhn
Last active December 23, 2016 00:30
Show Gist options
  • Save akuhn/01b815f5dcf36924bf5d to your computer and use it in GitHub Desktop.
Save akuhn/01b815f5dcf36924bf5d to your computer and use it in GitHub Desktop.
if defined? PryDebugger
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 'f', 'finish'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 's', 'step'
end
def __objects__(filter)
GC.disable
enum = ObjectSpace.each_object(filter)
before = enum.entries
yield
after = enum.entries
GC.enable
hash = {}
after.each { |each| hash[each.object_id] = each }
before.each { |each| hash.delete(each.object_id) }
hash.delete(after.object_id)
hash.delete(before.object_id)
hash.values
end
Pry.commands.block_command 'objects', 'Print created objects.', keep_retval: true do
target.eval "__objects__(false) { #{arg_string} }"
end
Pry.commands.block_command 'exceptions', 'Print created exceptions.', keep_retval: true do
target.eval "__objects__(Exception) { #{arg_string} }"
end
Pry.commands.block_command 'time', 'Benchmark expression and print seconds.' do
time = Time.now.to_f
target.eval(arg_string)
puts Time.now.to_f - time
end
Pry.commands.block_command 'footprint', 'Count created objects.' do
GC.disable
ObjectSpace.count_objects
GC.enable
calibrate = ''
GC.disable
c0 = ObjectSpace.count_objects
target.eval(calibrate)
c1 = ObjectSpace.count_objects
target.eval(arg_string)
c2 = ObjectSpace.count_objects
GC.enable
c2.keys.each do |key|
calibration = c1[key] - c0[key]
delta = c2[key] - c1[key]
print key.to_s.ljust(12)
print delta - calibration
puts
end
end
Pry.commands.block_command 'bytecode', 'Show bytecode.' do
puts RubyVM::InstructionSequence.compile(arg_string, nil, nil, nil, trace_instruction: false).disassemble
end
Pry.commands.block_command 'g', 'Search with bunnylol.' do
require 'cgi'
`open http://localhost:9393/?q=#{CGI::escape(arg_string)}`
end
unless defined? PryTree
$: << '/Users/adrian_kuhn/.rvm/gems/ruby-1.9.3-p551/gems/pry-tree-0.1.0/lib'
require 'pry-tree'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment