Class: TestProf::MemoryProf::Tracker

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

Overview

Tracker is responsible for tracking memory usage and determining the top n examples and groups. There are two types of trackers: AllocTracker and RssTracker.

A tracker consists of four main parts:

* list - a linked list that is being used to track memmory for individual groups/examples.
  list is an instance of LinkedList (for more info see tracker/linked_list.rb)
* examples – the top n examples, an instance of Utils::SizedOrderedSet.
* groups – the top n groups, an instance of Utils::SizedOrderedSet.
* track - a method that fetches the amount of memory in use at a certain point.

Direct Known Subclasses

AllocTracker, RssTracker

Defined Under Namespace

Modules: RssTool Classes: LinkedList, LinkedListNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(top_count) ⇒ Tracker

Returns a new instance of Tracker.



21
22
23
24
25
26
27
28
# File 'lib/test_prof/memory_prof/tracker.rb', line 21

def initialize(top_count)
  raise "Your Ruby Engine or OS is not supported" unless supported?

  @top_count = top_count

  @examples = Utils::SizedOrderedSet.new(top_count, sort_by: :memory)
  @groups = Utils::SizedOrderedSet.new(top_count, sort_by: :memory)
end

Instance Attribute Details

#examplesObject (readonly)

Returns the value of attribute examples.



19
20
21
# File 'lib/test_prof/memory_prof/tracker.rb', line 19

def examples
  @examples
end

#groupsObject (readonly)

Returns the value of attribute groups.



19
20
21
# File 'lib/test_prof/memory_prof/tracker.rb', line 19

def groups
  @groups
end

#listObject (readonly)

Returns the value of attribute list.



19
20
21
# File 'lib/test_prof/memory_prof/tracker.rb', line 19

def list
  @list
end

#top_countObject (readonly)

Returns the value of attribute top_count.



19
20
21
# File 'lib/test_prof/memory_prof/tracker.rb', line 19

def top_count
  @top_count
end

#total_memoryObject (readonly)

Returns the value of attribute total_memory.



19
20
21
# File 'lib/test_prof/memory_prof/tracker.rb', line 19

def total_memory
  @total_memory
end

Instance Method Details

#example_finished(example) ⇒ Object



43
44
45
46
# File 'lib/test_prof/memory_prof/tracker.rb', line 43

def example_finished(example)
  node = list.remove_node(example, track)
  examples << {**example, memory: node.total_memory}
end

#example_started(example) ⇒ Object



39
40
41
# File 'lib/test_prof/memory_prof/tracker.rb', line 39

def example_started(example)
  list.add_node(example, track)
end

#finishObject



34
35
36
37
# File 'lib/test_prof/memory_prof/tracker.rb', line 34

def finish
  node = list.remove_node(:total, track)
  @total_memory = node.total_memory
end

#group_finished(group) ⇒ Object



52
53
54
55
# File 'lib/test_prof/memory_prof/tracker.rb', line 52

def group_finished(group)
  node = list.remove_node(group, track)
  groups << {**group, memory: node.hooks_memory}
end

#group_started(group) ⇒ Object



48
49
50
# File 'lib/test_prof/memory_prof/tracker.rb', line 48

def group_started(group)
  list.add_node(group, track)
end

#startObject



30
31
32
# File 'lib/test_prof/memory_prof/tracker.rb', line 30

def start
  @list = LinkedList.new(track)
end