Class: Benelux::Timeline
- Includes:
- Selectable
- Defined in:
- lib/benelux/timeline.rb
Overview
|——----
–----
—-|
|
0.02
- Usage examples
-
Benelux.timeline.each do |mark|
p [mark.track, mark.name, mark.[:usecase], mark.[: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(track_id).regions(:execute)
Instance Attribute Summary collapse
-
#caller ⇒ Object
readonly
Returns the value of attribute caller.
-
#default_tags ⇒ Object
Returns the value of attribute default_tags.
-
#messages(tags = Selectable::Tags.new) ⇒ Object
Returns the value of attribute messages.
-
#ranges(name = nil, tags = Selectable::Tags.new) ⇒ Object
obj.ranges(:do_request) => [[:do_request_a, :do_request_z], [:do_request_a, …]].
-
#stats ⇒ Object
Returns the value of attribute stats.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #[](*tags) ⇒ Object
- #add_count(name, count, tags = {}) ⇒ Object
- #add_default_tags(tags = Selectable::Tags.new) ⇒ Object (also: #add_default_tag)
- #add_mark(name) ⇒ Object
-
#add_message(msg, tags = {}) ⇒ Object
msg
is the message to store. - #add_range(name, from, to) ⇒ Object
- #clear ⇒ Object
- #dump ⇒ Object
- #duration ⇒ Object
- #each(*args, &blk) ⇒ Object
-
#initialize(*args) ⇒ Timeline
constructor
A new instance of Timeline.
-
#marks(*names) ⇒ Object
obj.marks(:execute_a, :execute_z, :do_request_a) => [:execute_a, :do_request_a, :do_request_a, :execute_z].
- #merge!(*timelines) ⇒ Object
-
#regions(name = nil, tags = Selectable::Tags.new) ⇒ Object
obj.regions(:do_request) =>.
- #remove_default_tags(*tags) ⇒ Object
- #track ⇒ Object
Methods included from Selectable
#filter, #filter!, included, normalize, #rfilter, #tags
Constructor Details
#initialize(*args) ⇒ Timeline
Returns a new instance of Timeline.
27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Attribute Details
#caller ⇒ Object (readonly)
Returns the value of attribute caller.
26 27 28 |
# File 'lib/benelux/timeline.rb', line 26 def caller @caller end |
#default_tags ⇒ Object
Returns the value of attribute default_tags.
25 26 27 |
# File 'lib/benelux/timeline.rb', line 25 def @default_tags end |
#messages(tags = Selectable::Tags.new) ⇒ Object
Returns the value of attribute messages.
24 25 26 |
# File 'lib/benelux/timeline.rb', line 24 def @messages end |
#ranges(name = nil, tags = Selectable::Tags.new) ⇒ Object
obj.ranges(:do_request) =>
[[:do_request_a, :do_request_z], [:do_request_a, ...]]
96 97 98 |
# File 'lib/benelux/timeline.rb', line 96 def ranges @ranges end |
#stats ⇒ Object
Returns the value of attribute stats.
23 24 25 |
# File 'lib/benelux/timeline.rb', line 23 def stats @stats end |
Instance Method Details
#+(other) ⇒ Object
192 193 194 195 196 197 198 |
# File 'lib/benelux/timeline.rb', line 192 def +(other) self.push *other @ranges.push *other.ranges @messages.push *tl. @stats += other.stats self end |
#[](*tags) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/benelux/timeline.rb', line 77 def [](*) tl = super tl.ranges = @ranges.select do |region| region. >= end stats = Benelux::Stats.new @stats.each do |stat| next unless stat. >= stats += stat end tl. = tl.stats = stats tl end |
#add_count(name, count, tags = {}) ⇒ Object
157 158 159 160 161 162 |
# File 'lib/benelux/timeline.rb', line 157 def add_count(name, count, ={}) = .merge self. self.stats.add_group(name) self.stats.sample(name, count, ) count end |
#add_default_tags(tags = Selectable::Tags.new) ⇒ Object Also known as: add_default_tag
36 37 38 |
# File 'lib/benelux/timeline.rb', line 36 def (=Selectable::Tags.new) @default_tags.merge! end |
#add_mark(name) ⇒ Object
164 165 166 167 168 169 |
# File 'lib/benelux/timeline.rb', line 164 def add_mark(name) mark = Benelux::Mark.now(name) mark. self. self << mark mark end |
#add_message(msg, tags = {}) ⇒ Object
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.
147 148 149 150 151 152 153 154 155 |
# File 'lib/benelux/timeline.rb', line 147 def (msg, ={}) unless msg.kind_of?(Selectable::Object) msg = TaggableString.new msg.to_s end msg. self. msg. @messages << msg msg end |
#add_range(name, from, to) ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/benelux/timeline.rb', line 171 def add_range(name, from, to) range = Benelux::Range.new(name, from, to) range. self. range. from. range. to. self.ranges << range self.stats.add_group(name) self.stats.sample(name, range.duration, range.) range end |
#clear ⇒ Object
135 136 137 138 139 140 |
# File 'lib/benelux/timeline.rb', line 135 def clear @ranges.clear @stats.clear @messages.clear super end |
#dump ⇒ Object
48 49 50 |
# File 'lib/benelux/timeline.rb', line 48 def dump end |
#duration ⇒ Object
52 53 54 55 |
# File 'lib/benelux/timeline.rb', line 52 def duration return 0 if self.last.nil? self.last - self.first end |
#each(*args, &blk) ⇒ Object
57 58 59 60 61 62 63 |
# 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) ⇒ Object
obj.marks(:execute_a, :execute_z, :do_request_a) =>
[:execute_a, :do_request_a, :do_request_a, :execute_z]
69 70 71 72 73 74 75 |
# 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) ⇒ Object
182 183 184 185 186 187 188 189 190 |
# File 'lib/benelux/timeline.rb', line 182 def merge!(*timelines) timelines.each do |tl| self.push *tl @ranges.push *tl.ranges @messages.push *tl. @stats += tl.stats end self end |
#regions(name = nil, tags = Selectable::Tags.new) ⇒ Object
obj.regions(:do_request) =>
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/benelux/timeline.rb', line 109 def regions(name=nil, =Selectable::Tags.new) return self if name.nil? self.ranges(name, ).collect do |base_range| marks = self.sort.select do |mark| mark >= base_range.from && mark <= base_range.to && mark. >= base_range. end ranges = self.ranges.select do |range| range.from >= base_range.from && range.to <= base_range.to && range. >= base_range. end tl = Benelux::Timeline.new(marks) tl.ranges = ranges.sort tl end end |
#remove_default_tags(*tags) ⇒ Object
40 41 42 |
# File 'lib/benelux/timeline.rb', line 40 def (*) @default_tags.delete_if { |n,v| .member?(n) } end |
#track ⇒ Object
44 45 46 |
# File 'lib/benelux/timeline.rb', line 44 def track @default_tags[:track] end |