Class: Reporter
- Inherits:
-
Object
- Object
- Reporter
- Defined in:
- lib/shoes/profiler.rb
Instance Method Summary collapse
-
#initialize ⇒ Reporter
constructor
A new instance of Reporter.
- #record(event, method_name, time) ⇒ Object
- #result ⇒ Object
Constructor Details
#initialize ⇒ Reporter
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 |
#result ⇒ Object
100 101 102 |
# File 'lib/shoes/profiler.rb', line 100 def result [@methods, @calls] end |