Class: Cardio::Logger::Performance::Entry
- Inherits:
-
Object
- Object
- Cardio::Logger::Performance::Entry
- Defined in:
- lib/cardio/logger/performance/entry.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#category_duration ⇒ Object
readonly
Returns the value of attribute category_duration.
-
#children ⇒ Object
Returns the value of attribute children.
-
#children_cnt ⇒ Object
Returns the value of attribute children_cnt.
-
#context ⇒ Object
Returns the value of attribute context.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#level ⇒ Object
Returns the value of attribute level.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
- #add_children(child = false) ⇒ Object
- #continue_category_timer ⇒ Object
- #delete ⇒ Object
- #delete_children(child = false) ⇒ Object
- #has_younger_siblings? ⇒ Boolean
-
#initialize(parent, level, args) ⇒ Entry
constructor
A new instance of Entry.
- #pause_category_timer ⇒ Object
- #save_category_duration ⇒ Object
- #save_duration ⇒ Object
- #start_category_timer ⇒ Object
-
#to_s! ⇒ Object
deletes the children counts in order to print the tree; must be called in the right order.
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
#category ⇒ Object (readonly)
Returns the value of attribute category.
6 7 8 |
# File 'lib/cardio/logger/performance/entry.rb', line 6 def category @category end |
#category_duration ⇒ Object (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 |
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/cardio/logger/performance/entry.rb', line 5 def children @children end |
#children_cnt ⇒ Object
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 |
#context ⇒ Object
Returns the value of attribute context.
5 6 7 |
# File 'lib/cardio/logger/performance/entry.rb', line 5 def context @context end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
6 7 8 |
# File 'lib/cardio/logger/performance/entry.rb', line 6 def details @details end |
#duration ⇒ Object
Returns the value of attribute duration.
5 6 7 |
# File 'lib/cardio/logger/performance/entry.rb', line 5 def duration @duration end |
#level ⇒ Object
Returns the value of attribute level.
5 6 7 |
# File 'lib/cardio/logger/performance/entry.rb', line 5 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/cardio/logger/performance/entry.rb', line 6 def @message end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/cardio/logger/performance/entry.rb', line 5 def parent @parent end |
#valid ⇒ Object
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_timer ⇒ Object
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 |
#delete ⇒ Object
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
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_timer ⇒ Object
49 50 51 |
# File 'lib/cardio/logger/performance/entry.rb', line 49 def pause_category_timer save_category_duration end |
#save_category_duration ⇒ Object
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_duration ⇒ Object
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_timer ⇒ Object
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 |