lib/gestalt.rb in gestalt-0.0.4 vs lib/gestalt.rb in gestalt-0.0.5

- old
+ new

@@ -3,17 +3,34 @@ require 'rubygems' require 'formatador' class Gestalt - VERSION = '0.0.4' + VERSION = '0.0.5' attr_accessor :calls - def initialize(formatador = Formatador.new) + def initialize(options = {}) + options = { + 'call' => true, + 'c-call' => false, + :formatador => Formatador.new + }.merge!(options) + + @traceable_calls = [] + @traceable_returns = [] + if options['call'] + @traceable_calls << 'call' + @traceable_returns << 'return' + end + if options ['c-call'] + @traceable_calls << 'c-call' + @traceable_returns << 'c-return' + end + @calls = [] - @formatador = formatador + @formatador = options[:formatador] @stack = [] @totals = {} end def display_calls @@ -55,22 +72,20 @@ def run(&block) Kernel.set_trace_func( lambda do |event, file, line, id, binding, classname| case event - when 'call', 'c-call' - # p "call #{classname}##{id}" + when *@traceable_calls call = Gestalt::Call.new( :action => "#{classname}##{id}", :location => "#{file}:#{line}" ) unless @stack.empty? @stack.last.children.push(call) end @stack.push(call) - when 'return', 'c-return' - # p "return #{classname}##{id}" + when *@traceable_returns unless @stack.empty? # we get one of these when we set the trace_func call = @stack.pop call.finish if @stack.empty? @calls << call @@ -92,18 +107,18 @@ @calls << call end end end - def self.profile(formatador = Formatador.new, &block) - gestalt = new(formatador) + def self.profile(options = {}, &block) + gestalt = new(options) gestalt.run(&block) gestalt.display_profile end - def self.trace(formatador = Formatador.new, &block) - gestalt = new(formatador) + def self.trace(options = {}, &block) + gestalt = new(options) gestalt.run(&block) gestalt.display_calls end private @@ -143,9 +158,16 @@ end end Gestalt.trace do + + slow = Slow.new + slow.slowing + + end + + Gestalt.trace('c-call' => true) do slow = Slow.new slow.slowing end