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

Returns a new instance of Entry.



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/card/log.rb', line 341

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
  @children = []
  if @parent
    @parent.add_children self
    #@sibling_nr = @parent.children_cnt
  end
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



338
339
340
# File 'lib/card/log.rb', line 338

def children
  @children
end

#children_cntObject

Returns the value of attribute children_cnt.



338
339
340
# File 'lib/card/log.rb', line 338

def children_cnt
  @children_cnt
end

#contextObject

Returns the value of attribute context.



338
339
340
# File 'lib/card/log.rb', line 338

def context
  @context
end

#durationObject

Returns the value of attribute duration.



338
339
340
# File 'lib/card/log.rb', line 338

def duration
  @duration
end

#levelObject

Returns the value of attribute level.



338
339
340
# File 'lib/card/log.rb', line 338

def level
  @level
end

#messageObject (readonly)

Returns the value of attribute message.



339
340
341
# File 'lib/card/log.rb', line 339

def message
  @message
end

#parentObject

Returns the value of attribute parent.



338
339
340
# File 'lib/card/log.rb', line 338

def parent
  @parent
end

#validObject

Returns the value of attribute valid.



338
339
340
# File 'lib/card/log.rb', line 338

def valid
  @valid
end

Instance Method Details

#add_children(child = false) ⇒ Object



359
360
361
362
# File 'lib/card/log.rb', line 359

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

#deleteObject



378
379
380
381
# File 'lib/card/log.rb', line 378

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

#delete_children(child = false) ⇒ Object



364
365
366
367
368
# File 'lib/card/log.rb', line 364

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

end

#has_younger_siblings?Boolean

Returns:

  • (Boolean)


370
371
372
# File 'lib/card/log.rb', line 370

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

#save_durationObject



374
375
376
# File 'lib/card/log.rb', line 374

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

#to_htmlObject



403
404
405
406
407
408
409
410
# File 'lib/card/log.rb', line 403

def to_html
  @to_html ||= begin
    msg = "<span title='#{@details}'>"
    msg += @message if @message
    msg += "<span class='badge #{"badge-danger" if @duration > 100}'> %d.2ms </span>" % @duration if @duration
    msg += '</span>'
  end
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



390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/card/log.rb', line 390

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