Class: NewRelic::Agent::ThreadProfile::Node

Inherits:
Object
  • Object
show all
Includes:
Coerce
Defined in:
lib/new_relic/agent/thread_profiler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Coerce

#float, #int, #log_failure, #string

Constructor Details

#initialize(line, parent = nil) ⇒ Node

Returns a new instance of Node.



261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/new_relic/agent/thread_profiler.rb', line 261

def initialize(line, parent=nil)
  line =~ /(.*)\:(\d+)\:in `(.*)'/
  @file = $1
  @method = $3
  @line_no = $2.to_i
  @children = []
  @runnable_count = 0
  @to_prune = false
  @depth = 0

  parent.add_child(self) if parent
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



258
259
260
# File 'lib/new_relic/agent/thread_profiler.rb', line 258

def children
  @children
end

#depthObject

Returns the value of attribute depth.



259
260
261
# File 'lib/new_relic/agent/thread_profiler.rb', line 259

def depth
  @depth
end

#fileObject (readonly)

Returns the value of attribute file.



258
259
260
# File 'lib/new_relic/agent/thread_profiler.rb', line 258

def file
  @file
end

#line_noObject (readonly)

Returns the value of attribute line_no.



258
259
260
# File 'lib/new_relic/agent/thread_profiler.rb', line 258

def line_no
  @line_no
end

#methodObject (readonly)

Returns the value of attribute method.



258
259
260
# File 'lib/new_relic/agent/thread_profiler.rb', line 258

def method
  @method
end

#runnable_countObject

Returns the value of attribute runnable_count.



259
260
261
# File 'lib/new_relic/agent/thread_profiler.rb', line 259

def runnable_count
  @runnable_count
end

#to_pruneObject

Returns the value of attribute to_prune.



259
260
261
# File 'lib/new_relic/agent/thread_profiler.rb', line 259

def to_prune
  @to_prune
end

Class Method Details

.prune!(kids) ⇒ Object



311
312
313
314
# File 'lib/new_relic/agent/thread_profiler.rb', line 311

def self.prune!(kids)
  kids.delete_if { |child| child.to_prune }
  kids.each { |child| child.prune! }
end

Instance Method Details

#==(other) ⇒ Object



274
275
276
277
278
# File 'lib/new_relic/agent/thread_profiler.rb', line 274

def ==(other)
  @file == other.file &&
    @method == other.method &&
    @line_no == other.line_no
end

#add_child(child) ⇒ Object



302
303
304
305
# File 'lib/new_relic/agent/thread_profiler.rb', line 302

def add_child(child)
  child.depth = @depth + 1
  @children << child unless @children.include? child
end

#order_for_pruning(y) ⇒ Object

Descending order on count, ascending on depth of nodes



285
286
287
# File 'lib/new_relic/agent/thread_profiler.rb', line 285

def order_for_pruning(y)
  [-runnable_count, depth] <=> [-y.runnable_count, y.depth]
end

#prune!Object



307
308
309
# File 'lib/new_relic/agent/thread_profiler.rb', line 307

def prune!
  Node.prune!(@children)
end

#to_arrayObject



291
292
293
294
295
296
297
298
299
300
# File 'lib/new_relic/agent/thread_profiler.rb', line 291

def to_array
  [[
      string(@file),
      string(@method),
      int(@line_no)
    ],
    int(@runnable_count),
    0,
    @children.map {|c| c.to_array}]
end

#total_countObject



280
281
282
# File 'lib/new_relic/agent/thread_profiler.rb', line 280

def total_count
  @runnable_count
end