Class: Cardio::Logger::Performance::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/cardio/logger/performance/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, level, args) ⇒ Entry

Returns a new instance of Entry.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cardio/logger/performance/entry.rb', line 8

def initialize( parent, level, args )
  @start = Time.new
  start_category_timer
  @message = "#{ args[:title] ||  args[:method] || '' }"
  @message += ": #{ args[:message] }" if args[:message]
  @details = args[:details]
  @context = args[:context]
  @category = args[:category]

  @level = level
  @duration = nil
  @valid = true
  @parent = parent
  @children_cnt = 0
  @children = []
  if @parent
    @parent.add_children self
    #@sibling_nr = @parent.children_cnt
  end
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



6
7
8
# File 'lib/cardio/logger/performance/entry.rb', line 6

def category
  @category
end

#category_durationObject (readonly)

Returns the value of attribute category_duration.



6
7
8
# File 'lib/cardio/logger/performance/entry.rb', line 6

def category_duration
  @category_duration
end

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/cardio/logger/performance/entry.rb', line 5

def children
  @children
end

#children_cntObject

Returns the value of attribute children_cnt.



5
6
7
# File 'lib/cardio/logger/performance/entry.rb', line 5

def children_cnt
  @children_cnt
end

#contextObject

Returns the value of attribute context.



5
6
7
# File 'lib/cardio/logger/performance/entry.rb', line 5

def context
  @context
end

#detailsObject (readonly)

Returns the value of attribute details.



6
7
8
# File 'lib/cardio/logger/performance/entry.rb', line 6

def details
  @details
end

#durationObject

Returns the value of attribute duration.



5
6
7
# File 'lib/cardio/logger/performance/entry.rb', line 5

def duration
  @duration
end

#levelObject

Returns the value of attribute level.



5
6
7
# File 'lib/cardio/logger/performance/entry.rb', line 5

def level
  @level
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/cardio/logger/performance/entry.rb', line 6

def message
  @message
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/cardio/logger/performance/entry.rb', line 5

def parent
  @parent
end

#validObject

Returns the value of attribute valid.



5
6
7
# File 'lib/cardio/logger/performance/entry.rb', line 5

def valid
  @valid
end

Instance Method Details

#add_children(child = false) ⇒ Object



29
30
31
32
# File 'lib/cardio/logger/performance/entry.rb', line 29

def add_children child=false
  @children_cnt += 1
  @children << child if child
end

#continue_category_timerObject



59
60
61
62
63
# File 'lib/cardio/logger/performance/entry.rb', line 59

def continue_category_timer
  if @category
    @category_start = Time.now
  end
end

#deleteObject



70
71
72
73
# File 'lib/cardio/logger/performance/entry.rb', line 70

def delete
  @valid = false
  @parent.delete_children(self) if @parent
end

#delete_children(child = false) ⇒ Object



34
35
36
37
38
# File 'lib/cardio/logger/performance/entry.rb', line 34

def delete_children child=false
  @children_cnt -= 1
  @children.delete child if child

end

#has_younger_siblings?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cardio/logger/performance/entry.rb', line 40

def has_younger_siblings?
  @parent && @parent.children_cnt > 0 #@sibling_nr
end

#pause_category_timerObject



49
50
51
# File 'lib/cardio/logger/performance/entry.rb', line 49

def pause_category_timer
  save_category_duration
end

#save_category_durationObject



53
54
55
56
57
# File 'lib/cardio/logger/performance/entry.rb', line 53

def save_category_duration
  if @category
    @category_duration += (Time.now - @category_start) * 1000
  end
end

#save_durationObject



65
66
67
68
# File 'lib/cardio/logger/performance/entry.rb', line 65

def save_duration
  save_category_duration
  @duration = (Time.now - @start) * 1000
end

#start_category_timerObject



44
45
46
47
# File 'lib/cardio/logger/performance/entry.rb', line 44

def start_category_timer
  @category_duration = 0
  @category_start = Time.now
end

#to_s!Object

deletes the children counts in order to print the tree; must be called in the right order

More robuts but more expensive approach: use @sibling_nr instead of counting @children_cnt down, but @sibling_nr has to be updated for all siblings of an entry if the entry gets deleted due to min_time or max_depth restrictions in the config, so we have to save all children relations for that



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cardio/logger/performance/entry.rb', line 82

def to_s!
  @to_s ||= begin
    msg = indent
    msg += "(%d.2ms) " % @duration if @duration
    msg += @message if @message

    if @details
      msg +=  ", " + @details.to_s.gsub( "\n", "\n#{ indent(false) }#{' '* TAB_SIZE}" )
    end
    @parent.delete_children if @parent
    msg
  end
end