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(id:, item:, memory_at_start:, previous:) ⇒ LinkedListNode

Returns a new instance of LinkedListNode.



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

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

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#itemObject (readonly)

Returns the value of attribute item.



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

def item
  @item
end

#memory_at_finishObject (readonly)

Returns the value of attribute memory_at_finish.



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

def memory_at_finish
  @memory_at_finish
end

#memory_at_startObject (readonly)

Returns the value of attribute memory_at_start.



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

def memory_at_start
  @memory_at_start
end

#nested_memoryObject (readonly)

Returns the value of attribute nested_memory.



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

def nested_memory
  @nested_memory
end

#previousObject (readonly)

Returns the value of attribute previous.



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

def previous
  @previous
end

Instance Method Details

#finish(memory_at_finish) ⇒ Object



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

def finish(memory_at_finish)
  @memory_at_finish = memory_at_finish

  previous&.add_nested(self)
end

#hooks_memoryObject



103
104
105
# File 'lib/test_prof/memory_prof/tracker/linked_list.rb', line 103

def hooks_memory
  total_memory - nested_memory
end

#total_memoryObject



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

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