lib/gestalt.rb in gestalt-0.0.0 vs lib/gestalt.rb in gestalt-0.0.1
- old
+ new
@@ -40,45 +40,46 @@
Formatador.display_table(table)
Formatador.display_line
end
def run(&block)
- start
- yield
- stop
- end
-
- def start
Kernel.set_trace_func(
lambda do |event, file, line, id, binding, classname|
case event
when 'call', 'c-call'
# p "call #{classname}##{id}"
call = Gestalt::Call.new(
:action => "#{classname}##{id}",
- :location => "#{File.expand_path(file)}:#{line}",
- :started_at => Time.now.to_f
+ :location => "#{file}:#{line}"
)
unless @stack.empty?
@stack.last.children.push(call)
end
@stack.push(call)
when 'return', 'c-return'
# p "return #{classname}##{id}"
unless @stack.empty? # we get one of these when we set the trace_func
call = @stack.pop
- call.finished_at = Time.now.to_f
+ call.finish
if @stack.empty?
@calls << call
end
end
end
end
)
- end
-
- def stop
+ yield
Kernel.set_trace_func(nil)
+ @stack.pop # pop Kernel#set_trace_func(nil)
+ unless @stack.empty?
+ @stack.last.children.pop # pop Kernel#set_trace_func(nil)
+ end
+ while call = @stack.pop # leftovers, not sure why...
+ call.finish
+ if @stack.empty?
+ @calls << call
+ end
+ end
end
def self.profile(&block)
gestalt = new
gestalt.run(&block)