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(id) ⇒ Object



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

def example_finished(id)
  node = list.remove_node(id, track)
  return unless node

  examples << {**node.item, memory: node.total_memory}
end

#example_started(id, example = id) ⇒ Object



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

def example_started(id, example = id)
  list.add_node(id, 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(id) ⇒ Object



54
55
56
57
58
59
# File 'lib/test_prof/memory_prof/tracker.rb', line 54

def group_finished(id)
  node = list.remove_node(id, track)
  return unless node

  groups << {**node.item, memory: node.hooks_memory}
end

#group_started(id, group = id) ⇒ Object



50
51
52
# File 'lib/test_prof/memory_prof/tracker.rb', line 50

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

#startObject



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

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