Class: NewRelic::Agent::Threading::BacktraceRoot

Inherits:
BacktraceBase show all
Defined in:
lib/new_relic/agent/threading/backtrace_node.rb

Instance Attribute Summary collapse

Attributes inherited from BacktraceBase

#children

Instance Method Summary collapse

Methods inherited from BacktraceBase

#add_child, #add_child_unless_present, #find_child

Constructor Details

#initializeBacktraceRoot

Returns a new instance of BacktraceRoot.



37
38
39
40
# File 'lib/new_relic/agent/threading/backtrace_node.rb', line 37

def initialize
  super
  @flattened = []
end

Instance Attribute Details

#flattenedObject (readonly)

Returns the value of attribute flattened.



35
36
37
# File 'lib/new_relic/agent/threading/backtrace_node.rb', line 35

def flattened
  @flattened
end

Instance Method Details

#==(other) ⇒ Object



42
43
44
# File 'lib/new_relic/agent/threading/backtrace_node.rb', line 42

def ==(other)
  true # all roots are at the same depth and have no raw_line
end

#aggregate(backtrace) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/new_relic/agent/threading/backtrace_node.rb', line 50

def aggregate(backtrace)
  current = self

  depth = 0
  backtrace.reverse_each do |frame|
    break if depth >= MAX_THREAD_PROFILE_DEPTH

    existing_node = current.find_child(frame)
    if existing_node
      node = existing_node
    else
      node = Threading::BacktraceNode.new(frame)
      current.add_child(node)
      @flattened << node
    end

    node.runnable_count += 1
    current = node
    depth += 1
  end
end

#as_arrayObject



46
47
48
# File 'lib/new_relic/agent/threading/backtrace_node.rb', line 46

def as_array
  @children.map { |c| c.as_array }.compact
end

#dump_stringObject



72
73
74
75
76
77
# File 'lib/new_relic/agent/threading/backtrace_node.rb', line 72

def dump_string
  result = +"#<BacktraceRoot:#{object_id}>"
  child_results = @children.map { |c| c.dump_string(2) }.join("\n")
  result << "\n" unless child_results.empty?
  result << child_results
end