Class: Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/shoes/profiler.rb

Instance Method Summary collapse

Constructor Details

#initializeReporter

Returns a new instance of Reporter



75
76
77
78
79
80
81
82
# File 'lib/shoes/profiler.rb', line 75

def initialize
    # A stack for pushing/popping methods when methods get called/returned
    @call_stack = []
    # Nodes for all methods
    @methods = {}
    # Connections between the nodes
    @calls = {}
end

Instance Method Details

#record(event, method_name, time) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/shoes/profiler.rb', line 84

def record(event, method_name, time)
    case event
    when :call, :c_call
        @call_stack << CallInfo.new(method_name, time)
    when :return, :c_return
        # Return cannot be the first event in the call stack
        return if @call_stack.empty?

        method = @call_stack.pop
        # Set execution time of method in call info
        method.time = time - method.time
        
        add_method_to_call_tree(method)
    end
end

#resultObject



100
101
102
# File 'lib/shoes/profiler.rb', line 100

def result
    [@methods, @calls]
end