Class: Fiveruns::Tuneup::RootStep

Inherits:
Object
  • Object
show all
Includes:
Templating
Defined in:
lib/fiveruns/tuneup/step.rb

Direct Known Subclasses

Step

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Templating

#h, #to_html

Constructor Details

#initialize(time = nil) ⇒ RootStep

Returns a new instance of RootStep.



25
26
27
28
29
# File 'lib/fiveruns/tuneup/step.rb', line 25

def initialize(time = nil)
  @time = time
  @children = []
  @bar = Bar.new(self)
end

Instance Attribute Details

#barObject (readonly)

Returns the value of attribute bar.



23
24
25
# File 'lib/fiveruns/tuneup/step.rb', line 23

def bar
  @bar
end

#childrenObject (readonly)

Returns the value of attribute children.



23
24
25
# File 'lib/fiveruns/tuneup/step.rb', line 23

def children
  @children
end

#parentObject

Returns the value of attribute parent.



24
25
26
# File 'lib/fiveruns/tuneup/step.rb', line 24

def parent
  @parent
end

#timeObject

Returns the value of attribute time.



24
25
26
# File 'lib/fiveruns/tuneup/step.rb', line 24

def time
  @time
end

Instance Method Details

#add_child(child) ⇒ Object



50
51
52
53
# File 'lib/fiveruns/tuneup/step.rb', line 50

def add_child(child)
  child.parent = self
  children << child
end

#disparityObject



41
42
43
44
45
46
47
48
49
# File 'lib/fiveruns/tuneup/step.rb', line 41

def disparity
  result = time - children.inject(0) { |sum, child| sum + child.time }
  if result < 0
    #TODO resolve instances where sum of child times exceed parent time
    #raise CalculationError, "Child steps exceed parent step size"
    result = 0
  end
  result
end

#format_time(time) ⇒ Object



54
55
56
# File 'lib/fiveruns/tuneup/step.rb', line 54

def format_time(time)
  '%.2fms' % (time * 1000)
end

#layer_portionsObject



57
58
59
# File 'lib/fiveruns/tuneup/step.rb', line 57

def layer_portions
  children.first.layer_portions
end

#proportionObject



64
65
66
# File 'lib/fiveruns/tuneup/step.rb', line 64

def proportion
  time / root.time
end

#recordObject



35
36
37
38
39
40
# File 'lib/fiveruns/tuneup/step.rb', line 35

def record
  start = Time.now
  result = Step.inside(self) { yield }
  @time = Time.now - start
  result
end

#rootObject



31
32
33
# File 'lib/fiveruns/tuneup/step.rb', line 31

def root
  parent ? parent.root : self
end

#templateObject



72
73
74
75
76
77
78
79
# File 'lib/fiveruns/tuneup/step.rb', line 72

def template
  %(
    <div id="tuneup-summary">
      <%= bar.to_html %>
      <%= (time * 1000).to_i %> ms
    </div>
  )
end

#to_html_with_childrenObject



68
69
70
# File 'lib/fiveruns/tuneup/step.rb', line 68

def to_html_with_children
  to_html << children.map { |c| c.to_html }.join
end

#to_jsonObject



60
61
62
# File 'lib/fiveruns/tuneup/step.rb', line 60

def to_json
  {:children => children, :time => time}.to_json
end