class TestProf::MemoryProf::Tracker::LinkedList
used by hooks and other code inside a group by subtracting nested_memory from total_memory.
of memory used by its nested examples/groups, and thus we will be able to calculate the memory
“when not published” nested_memory. So when the group finishes we will have the total amount
group contains other examples or sub-groups, their total_memory will also be added to
memory usage to nested_memory of the “when not published” node. If the “when not published”
In the example above, after we remove the node “makes the question visible”, we add its total
gradually tracking the amount of memory used by nested examples inside a group.
When we remove a node we add its total_memory to the previous node.nested_memory, thus
example/group has finished and it is time to calculate its memory usage.
* remove_node – removes and returns the head node from the list. It means that the node
has started and we track how much memory has already been used.
* add_node – adds a node to the beginig of the list. At this point an example or group
LinkedList supports two method for working with it:
^“makes the question visible” -> “when not published” -> “#publish” -> Question
(^ denotes the head node):
At the moment when rspec is executing the example, the list has the following structure
end
end
end
end
…
it “makes the question visible” do
context “when not published” do
decribe “#publish” do
describe Question do
For example, if we have the following spec:
current examples/groups, then the head node will always point to a leaf in that tree.
If we picture a linked list as a tree with root being the top level group and leaves being
Each node has a link to its previous node, and the head node points to the current example/group.
* previous - a link to the previous node
* nested_memory - the amount of memory allocated by examples/groups defined inside a group
* memory_at_finish - the amount of memory at the end of an example/group
* memory_at_start - the amount of memory at the start of an example/group
A list node (‘LinkedListNode`) represents an example/group and its memory usage info:
LinkedList is a linked list that track memory usage for individual examples/groups.
def add_node(id, item, memory_at_start)
def add_node(id, item, memory_at_start) @head = LinkedListNode.new( id: id, item: item, previous: head, memory_at_start: memory_at_start ) end
def initialize(memory_at_start)
def initialize(memory_at_start) add_node(:total, :total, memory_at_start) end
def remove_node(id, memory_at_finish)
def remove_node(id, memory_at_finish) return if head.id != id head.finish(memory_at_finish) current = head @head = head.previous current end