Class: RequireProf::RequireTree

Inherits:
Object
  • Object
show all
Defined in:
lib/require_prof/require_tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ RequireTree

Returns a new instance of RequireTree.



7
8
9
10
11
12
13
14
15
# File 'lib/require_prof/require_tree.rb', line 7

def initialize(name)
  @name = name
  @children = {}
  @time = 0.0
  @total_time = 0.0
  @overhead_time = 0.0
  @memory = 0.0
  @total_memory = 0.0
end

Instance Attribute Details

#memoryObject

Returns the value of attribute memory.



5
6
7
# File 'lib/require_prof/require_tree.rb', line 5

def memory
  @memory
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/require_prof/require_tree.rb', line 4

def name
  @name
end

#overhead_timeObject

Returns the value of attribute overhead_time.



5
6
7
# File 'lib/require_prof/require_tree.rb', line 5

def overhead_time
  @overhead_time
end

#timeObject

Returns the value of attribute time.



5
6
7
# File 'lib/require_prof/require_tree.rb', line 5

def time
  @time
end

#total_memoryObject

Returns the value of attribute total_memory.



5
6
7
# File 'lib/require_prof/require_tree.rb', line 5

def total_memory
  @total_memory
end

#total_timeObject

Returns the value of attribute total_time.



5
6
7
# File 'lib/require_prof/require_tree.rb', line 5

def total_time
  @total_time
end

Instance Method Details

#<<(tree) ⇒ Object



17
18
19
# File 'lib/require_prof/require_tree.rb', line 17

def <<(tree)
  @children[tree.name] ||= tree
end

#[](name) ⇒ Object



21
22
23
# File 'lib/require_prof/require_tree.rb', line 21

def [](name)
  @children[name]
end

#childrenObject



25
26
27
# File 'lib/require_prof/require_tree.rb', line 25

def children
  @children.values
end

#process_memoryObject



36
37
38
39
# File 'lib/require_prof/require_tree.rb', line 36

def process_memory
  children.map(&:process_memory)
  @memory = total_memory - children.map(&:total_memory).reduce(:+).to_f
end

#process_timeObject



29
30
31
32
33
34
# File 'lib/require_prof/require_tree.rb', line 29

def process_time
  children.map(&:process_time)
  @overhead_time += children.map(&:overhead_time ).reduce(:+).to_f
  @total_time -= overhead_time
  @time = total_time - children.map(&:total_time).reduce(:+).to_f
end

#to_hObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/require_prof/require_tree.rb', line 41

def to_h
  {
    name: name,
    children: children.map(&:to_h),
    time: time,
    total_time: total_time,
    memory: memory,
    total_memory: total_memory
  }
end