Class: TestProf::MemoryProf::Tracker::LinkedListNode

Inherits:
Object
  • Object
show all
Defined in:
lib/test_prof/memory_prof/tracker/linked_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item:, memory_at_start:, previous:) ⇒ LinkedListNode

Returns a new instance of LinkedListNode.



80
81
82
83
84
85
86
87
# File 'lib/test_prof/memory_prof/tracker/linked_list.rb', line 80

def initialize(item:, memory_at_start:, previous:)
  @item = item
  @previous = previous

  @memory_at_start = memory_at_start || 0
  @memory_at_finish = nil
  @nested_memory = 0
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



78
79
80
# File 'lib/test_prof/memory_prof/tracker/linked_list.rb', line 78

def item
  @item
end

#memory_at_finishObject (readonly)

Returns the value of attribute memory_at_finish.



78
79
80
# File 'lib/test_prof/memory_prof/tracker/linked_list.rb', line 78

def memory_at_finish
  @memory_at_finish
end

#memory_at_startObject (readonly)

Returns the value of attribute memory_at_start.



78
79
80
# File 'lib/test_prof/memory_prof/tracker/linked_list.rb', line 78

def memory_at_start
  @memory_at_start
end

#nested_memoryObject (readonly)

Returns the value of attribute nested_memory.



78
79
80
# File 'lib/test_prof/memory_prof/tracker/linked_list.rb', line 78

def nested_memory
  @nested_memory
end

#previousObject (readonly)

Returns the value of attribute previous.



78
79
80
# File 'lib/test_prof/memory_prof/tracker/linked_list.rb', line 78

def previous
  @previous
end

Instance Method Details

#finish(memory_at_finish) ⇒ Object



105
106
107
108
109
# File 'lib/test_prof/memory_prof/tracker/linked_list.rb', line 105

def finish(memory_at_finish)
  @memory_at_finish = memory_at_finish

  previous&.add_nested(self)
end

#hooks_memoryObject



101
102
103
# File 'lib/test_prof/memory_prof/tracker/linked_list.rb', line 101

def hooks_memory
  total_memory - nested_memory
end

#total_memoryObject



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/test_prof/memory_prof/tracker/linked_list.rb', line 89

def total_memory
  return 0 if memory_at_finish.nil?
  # It seems that on Windows Minitest may release a lot of memory to
  # the OS when it finishes and executes #report, leading to memory_at_finish
  # being less than memory_at_start. In this case we return nested_memory
  # which does not account for the memory used in `after` hooks, but it
  # is better than nothing.
  return nested_memory if memory_at_start > memory_at_finish

  memory_at_finish - memory_at_start
end