Skip to content

Commit

Permalink
Timeline#messages
Browse files Browse the repository at this point in the history
  • Loading branch information
delano committed Nov 2, 2009
1 parent da102ad commit c8b0c2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ BENELUX, CHANGES
* ADDED: Thread#rotate_timeline * ADDED: Thread#rotate_timeline
* ADDED: Stats#clear * ADDED: Stats#clear
* ADDED: Selectable#rfilter * ADDED: Selectable#rfilter
* ADDED: Timeline#messages



#### 0.5.0 (2009-10-21) ############################### #### 0.5.0 (2009-10-21) ###############################


Expand Down
3 changes: 2 additions & 1 deletion lib/benelux.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def Benelux.current_track(name=nil,group=nil)
end end
Benelux.current_track :main Benelux.current_track :main


# Only updates data from threads that are dead # Only updates data from threads that
# are dead and rotated timelines.
def Benelux.update_global_timeline def Benelux.update_global_timeline
@@mutex.synchronize do @@mutex.synchronize do
dthreads = Benelux.known_threads.select { |t| dthreads = Benelux.known_threads.select { |t|
Expand Down
29 changes: 25 additions & 4 deletions lib/benelux/timeline.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ class Timeline < Array
include Selectable include Selectable
attr_accessor :ranges attr_accessor :ranges
attr_accessor :stats attr_accessor :stats
attr_accessor :messages
attr_accessor :default_tags attr_accessor :default_tags
attr_reader :caller attr_reader :caller
def initialize(*args) def initialize(*args)
@caller = Kernel.caller @caller = Kernel.caller
@ranges = SelectableArray.new @ranges = SelectableArray.new
@default_tags = Selectable::Tags.new @default_tags = Selectable::Tags.new
@stats = Benelux::Stats.new @stats = Benelux::Stats.new
@messages = SelectableArray.new
add_default_tag :thread_id => Thread.current.object_id.abs add_default_tag :thread_id => Thread.current.object_id.abs
super super
end end
Expand Down Expand Up @@ -81,6 +83,7 @@ def [](*tags)
next unless stat.tags >= tags next unless stat.tags >= tags
stats += stat stats += stat
end end
tl.messages = messages
tl.stats = stats tl.stats = stats
tl tl
end end
Expand Down Expand Up @@ -121,12 +124,28 @@ def regions(name=nil, tags=Selectable::Tags.new)
end end
end end


def messages(tags=Selectable::Tags.new)
ret = @messages.select do |msg|
(tags.nil? || msg.tags >= tags)
end
SelectableArray.new ret
end

def clear def clear
@ranges.clear @ranges.clear
@stats.clear @stats.clear
@messages.clear
super super
end end


def add_message(str, tags={})
msg = TaggableString.new str
msg.add_tags self.default_tags
msg.add_tags tags
@messages << msg
msg
end

def add_count(name, count, tags={}) def add_count(name, count, tags={})
tags = tags.merge self.default_tags tags = tags.merge self.default_tags
self.stats.add_group(name) self.stats.add_group(name)
Expand Down Expand Up @@ -155,16 +174,18 @@ def add_range(name, from, to)
def merge!(*timelines) def merge!(*timelines)
timelines.each do |tl| timelines.each do |tl|
self.push *tl self.push *tl
self.ranges.push *tl.ranges @ranges.push *tl.ranges
self.stats += tl.stats @messages.push *tl.messages
@stats += tl.stats
end end
self self
end end


def +(other) def +(other)
self.push *other self.push *other
self.ranges.push *other.ranges @ranges.push *other.ranges
self.stats += other.stats @messages.push *tl.messages
@stats += other.stats
self self
end end
# Needs to compare thread id and call id. # Needs to compare thread id and call id.
Expand Down

0 comments on commit c8b0c2a

Please sign in to comment.