Class: Card::Log::Performance::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/card/log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, level, args) ⇒ Entry



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/card/log.rb', line 258

def initialize( parent, level, args )
  @start = Time.new
  @message = "#{ args[:title] ||  args[:method] || '' }"
  @message += ": #{ args[:message] }" if args[:message]
  @details = args[:details]
  @context = args[:context]
  @level = level
  @duration = nil
  @valid = true
  @parent = parent
  @children_cnt = 0
  if @parent
    @parent.add_children
    #@sibling_nr = @parent.children_cnt
  end
end

Instance Attribute Details

#children_cntObject

Returns the value of attribute children_cnt.



256
257
258
# File 'lib/card/log.rb', line 256

def children_cnt
  @children_cnt
end

#contextObject

Returns the value of attribute context.



256
257
258
# File 'lib/card/log.rb', line 256

def context
  @context
end

#durationObject

Returns the value of attribute duration.



256
257
258
# File 'lib/card/log.rb', line 256

def duration
  @duration
end

#levelObject

Returns the value of attribute level.



256
257
258
# File 'lib/card/log.rb', line 256

def level
  @level
end

#parentObject

Returns the value of attribute parent.



256
257
258
# File 'lib/card/log.rb', line 256

def parent
  @parent
end

#validObject

Returns the value of attribute valid.



256
257
258
# File 'lib/card/log.rb', line 256

def valid
  @valid
end

Instance Method Details

#add_childrenObject



275
276
277
# File 'lib/card/log.rb', line 275

def add_children
  @children_cnt += 1
end

#deleteObject



291
292
293
294
# File 'lib/card/log.rb', line 291

def delete
  @valid = false
  @parent.delete_children if @parent
end

#delete_childrenObject



279
280
281
# File 'lib/card/log.rb', line 279

def delete_children
  @children_cnt -= 1
end

#has_younger_siblings?Boolean



283
284
285
# File 'lib/card/log.rb', line 283

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

#save_durationObject



287
288
289
# File 'lib/card/log.rb', line 287

def save_duration
  @duration = (Time.now - @start) * 1000
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



303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/card/log.rb', line 303

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