Class: RequireProf::RequireTree
- Inherits:
-
Object
- Object
- RequireProf::RequireTree
- Defined in:
- lib/require_prof/require_tree.rb
Instance Attribute Summary collapse
-
#memory ⇒ Object
Returns the value of attribute memory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#overhead_time ⇒ Object
Returns the value of attribute overhead_time.
-
#time ⇒ Object
Returns the value of attribute time.
-
#total_memory ⇒ Object
Returns the value of attribute total_memory.
-
#total_time ⇒ Object
Returns the value of attribute total_time.
Instance Method Summary collapse
- #<<(tree) ⇒ Object
- #[](name) ⇒ Object
- #children ⇒ Object
-
#initialize(name) ⇒ RequireTree
constructor
A new instance of RequireTree.
- #process_memory ⇒ Object
- #process_time ⇒ Object
- #to_h ⇒ Object
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
#memory ⇒ Object
Returns the value of attribute memory.
5 6 7 |
# File 'lib/require_prof/require_tree.rb', line 5 def memory @memory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/require_prof/require_tree.rb', line 4 def name @name end |
#overhead_time ⇒ Object
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 |
#time ⇒ Object
Returns the value of attribute time.
5 6 7 |
# File 'lib/require_prof/require_tree.rb', line 5 def time @time end |
#total_memory ⇒ Object
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_time ⇒ Object
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 |
#children ⇒ Object
25 26 27 |
# File 'lib/require_prof/require_tree.rb', line 25 def children @children.values end |
#process_memory ⇒ Object
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_time ⇒ Object
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_h ⇒ Object
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 |