class Benelux::Timeline

|------+----+--+----+----|
       |
      0.02
Usage examples

Benelux.timeline.each do |mark|

p [mark.track, mark.name, mark.tags[:usecase], mark.tags[:call_id]]

end

Benelux.timeline.ranges(:do_request).each do |range|

puts "Client%s: %s: %s: %f" % [range.track, range.thread_id, range.name, range.duration]

end

regions = Benelux.timeline.regions(:execute)

Attributes

caller[R]
default_tags[RW]
messages[RW]
ranges[RW]
stats[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/benelux/timeline.rb, line 27
def initialize(*args)
  @caller = Kernel.caller
  @ranges = SelectableArray.new
  @default_tags = Selectable::Tags.new
  @stats = Benelux::Stats.new
  @messages = SelectableArray.new
  add_default_tag :thread_id => Thread.current.object_id.abs
  super
end

Public Instance Methods

+(other) click to toggle source
# File lib/benelux/timeline.rb, line 192
def +(other)
  self.push *other
  @ranges.push *other.ranges
  @messages.push *tl.messages
  @stats += other.stats
  self
end
[](*tags) click to toggle source
Calls superclass method
# File lib/benelux/timeline.rb, line 77
def [](*tags)
  tl = super
  tl.ranges = @ranges.select do |region|
    region.tags >= tags
  end
  stats = Benelux::Stats.new
  @stats.each do |stat|
    next unless stat.tags >= tags
    stats += stat
  end
  tl.messages = messages
  tl.stats = stats
  tl
end
add_count(name, count, tags={}) click to toggle source
# File lib/benelux/timeline.rb, line 157
def add_count(name, count, tags={})
  tags = tags.merge self.default_tags
  self.stats.add_group(name)
  self.stats.sample(name, count, tags)
  count
end
add_default_tag(tags=Selectable::Tags.new)
Alias for: add_default_tags
add_default_tags(tags=Selectable::Tags.new) click to toggle source
# File lib/benelux/timeline.rb, line 36
def add_default_tags(tags=Selectable::Tags.new)
  @default_tags.merge! tags
end
Also aliased as: add_default_tag, add_default_tag
add_mark(name) click to toggle source
# File lib/benelux/timeline.rb, line 164
def add_mark(name)
  mark = Benelux::Mark.now(name)
  mark.add_tags self.default_tags
  self << mark
  mark
end
add_message(msg, tags={}) click to toggle source

msg is the message to store. This can be any type of object that includes Selectable::Object (so that tags can be added to the message to retreive it later). If msg does not include Selectable::Object it will be converted to a TaggableString object.

# File lib/benelux/timeline.rb, line 147
def add_message(msg, tags={})
  unless msg.kind_of?(Selectable::Object)
    msg = TaggableString.new msg.to_s
  end
  msg.add_tags self.default_tags
  msg.add_tags tags
  @messages << msg
  msg
end
add_range(name, from, to) click to toggle source
# File lib/benelux/timeline.rb, line 171
def add_range(name, from, to)
  range = Benelux::Range.new(name, from, to)
  range.add_tags self.default_tags
  range.add_tags from.tags
  range.add_tags to.tags
  self.ranges << range
  self.stats.add_group(name)
  self.stats.sample(name, range.duration, range.tags)
  range
end
clear() click to toggle source
Calls superclass method
# File lib/benelux/timeline.rb, line 135
def clear
  @ranges.clear
  @stats.clear
  @messages.clear
  super
end
dump() click to toggle source
# File lib/benelux/timeline.rb, line 48
def dump
   
end
duration() click to toggle source
# File lib/benelux/timeline.rb, line 52
def duration
  return 0 if self.last.nil?
  self.last - self.first
end
each(*args, &blk) click to toggle source
Calls superclass method
# File lib/benelux/timeline.rb, line 57
def each(*args, &blk)
  if args.empty? 
    super(&blk) 
  else 
    self.marks(*args).each(&blk)
  end
end
marks(*names) click to toggle source

obj.marks(:execute_a, :execute_z, :do_request_a) =>

[:execute_a, :do_request_a, :do_request_a, :execute_z]
# File lib/benelux/timeline.rb, line 69
def marks(*names)
  return self if names.empty?
  names = names.flatten.collect { |n| n.to_s }
  self.select do |mark| 
    names.member? mark.name.to_s
  end
end
merge!(*timelines) click to toggle source
# File lib/benelux/timeline.rb, line 182
def merge!(*timelines)
  timelines.each do |tl| 
    self.push *tl
    @ranges.push *tl.ranges
    @messages.push *tl.messages
    @stats += tl.stats
  end
  self
end
regions(name=nil, tags=Selectable::Tags.new) click to toggle source

obj.regions(:do_request) =>

# File lib/benelux/timeline.rb, line 109
def regions(name=nil, tags=Selectable::Tags.new)
  return self if name.nil?
  self.ranges(name, tags).collect do |base_range|
    marks = self.sort.select do |mark|
      mark >= base_range.from && 
      mark <= base_range.to &&
      mark.tags >= base_range.tags
    end
    ranges = self.ranges.select do |range|
      range.from >= base_range.from &&
      range.to <= base_range.to &&
      range.tags >= base_range.tags
    end
    tl = Benelux::Timeline.new(marks)
    tl.ranges = ranges.sort
    tl
  end
end
remove_default_tags(*tags) click to toggle source
# File lib/benelux/timeline.rb, line 40
def remove_default_tags(*tags)
  @default_tags.delete_if { |n,v| tags.member?(n) }
end
track() click to toggle source
# File lib/benelux/timeline.rb, line 44
def track 
  @default_tags[:track]
end