class RequireProf::Profile
Public Class Methods
new()
click to toggle source
# File lib/require_prof/profile.rb, line 8 def initialize @running = false @paused = false @root = RequireTree.new('.') @stack = [@root] end
Public Instance Methods
pause()
click to toggle source
# File lib/require_prof/profile.rb, line 28 def pause @paused = true end
paused?()
click to toggle source
# File lib/require_prof/profile.rb, line 19 def paused? @paused end
require(name)
click to toggle source
# File lib/require_prof/profile.rb, line 43 def require(name) node = RequireTree.new(name) @stack.last << node @stack << node begin time_before = Time.now.to_f if MemorySampler.available? memory_before = MemorySampler.memory_usage overhead_time_before = Time.now.to_f - time_before end rp_original_require name ensure @stack.pop if MemorySampler.available? tmp_time = Time.now.to_f memory_after = MemorySampler.memory_usage overhead_time_after = Time.now.to_f - tmp_time end time_after = Time.now.to_f end node.total_time = (time_after - time_before) * 1000 if MemorySampler.available? node.total_memory = memory_after - memory_before node.overhead_time = (overhead_time_before + overhead_time_after) * 1000 end end
resume()
click to toggle source
# File lib/require_prof/profile.rb, line 32 def resume @paused = false end
running?()
click to toggle source
# File lib/require_prof/profile.rb, line 15 def running? @running end
start()
click to toggle source
# File lib/require_prof/profile.rb, line 23 def start install_hook @running = true end
stop()
click to toggle source
# File lib/require_prof/profile.rb, line 36 def stop remove_hook @running = false post_process @root end
Private Instance Methods
install_hook()
click to toggle source
# File lib/require_prof/profile.rb, line 72 def install_hook ::Kernel.send(:define_method, :require) { |file| RequireProf.require file } end
post_process()
click to toggle source
# File lib/require_prof/profile.rb, line 80 def post_process @root.process_time @root.process_memory end
remove_hook()
click to toggle source
# File lib/require_prof/profile.rb, line 76 def remove_hook ::Kernel.send :alias_method, :require, :rp_original_require end