Class: Codebeacon::Tracer::CallTree

Inherits:
Object
  • Object
show all
Defined in:
lib/codebeacon/tracer/src/models/call_tree.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thread) ⇒ CallTree

Returns a new instance of CallTree.



15
16
17
18
19
20
21
22
23
24
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 15

def initialize(thread)
  @thread = thread
  root_name = (thread.name || "thread") + " (#{CallTree.next_thread_id})"
  @root = TreeNode.new(method: root_name)
  @root.file, @root.line = __FILE__, __LINE__
  @current_node = @root
  @depth = 0
  @call_count = 0
  @block_call_count = 0
end

Instance Attribute Details

#block_call_countObject (readonly)

Returns the value of attribute block_call_count.



7
8
9
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 7

def block_call_count
  @block_call_count
end

#call_countObject (readonly)

Returns the value of attribute call_count.



7
8
9
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 7

def call_count
  @call_count
end

#current_nodeObject (readonly)

Returns the value of attribute current_node.



7
8
9
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 7

def current_node
  @current_node
end

#depthObject (readonly)

Returns the value of attribute depth.



7
8
9
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 7

def depth
  @depth
end

#rootObject (readonly)

Returns the value of attribute root.



7
8
9
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 7

def root
  @root
end

#threadObject (readonly)

Returns the value of attribute thread.



7
8
9
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 7

def thread
  @thread
end

Class Method Details

.next_thread_idObject



9
10
11
12
13
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 9

def self.next_thread_id
  @thread_id_mutex.synchronize do
    @thread_id += 1
  end
end

Instance Method Details

#add_block_callObject



35
36
37
38
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 35

def add_block_call()
  @block_call_count += 1
  add_node()
end

#add_callObject



30
31
32
33
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 30

def add_call()
  @call_count += 1
  add_node()
end

#add_nodeObject



40
41
42
43
44
45
46
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 40

def add_node()
  new_node = TreeNode.new()
  @current_node.children << new_node
  new_node.parent = @current_node
  @depth += 1
  @current_node = new_node
end

#add_returnObject



48
49
50
51
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 48

def add_return()
  @depth -= 1
  @current_node = @current_node.parent if @current_node
end

#total_call_countObject



26
27
28
# File 'lib/codebeacon/tracer/src/models/call_tree.rb', line 26

def total_call_count
  @call_count + @block_call_count
end